有许多具有已知 ID 和相同类的 div。我们需要设置 ::after 伪元素的样式,以便每个伪元素的颜色不同。Jquery 或 JavaScript 中需要该解决方案。此代码错误地分配了样式
$(document).ready(function() {
$('#' + 1318735 + '.top-circle::after').css('background-image', 'radial-gradient(110% 100% at 50% 0%, rgba(0, 0, 0, 0) 50%, rgb(32, 178, 170) 51%, rgb(32, 178, 170) 0px');
});
此代码为伪元素创建样式,并且没有为具有给定 id 的 div 分配类。
$( "<style>.top-circle::after { background-image: radial-gradient(110% 100% at 50% 0%, rgba(0, 0, 0, 0) 50%, rgb(32, 178, 170) 51%, rgb(32, 178, 170) 0px); }</style>" ).appendTo( "#1318735" );
Divas 是在循环中生成的,因此不能为每个 div 分配单独的附加类。
<? foreach($arResult["ITEMS"] as $arItem):?>
<div id="<?= $arItem['ID']?>" class="top-circle akziya_img_wrapper akzii"><div>
<?endforeach;?>
这是来自模板 1-s itrix 的片段
不能用 JS 或 JQ 操作伪元素,但可以使用CSS 变量
例如:
选项
$('#' + 1318735 + '.top-circle::after')不起作用,jQuery 选择器不适用于伪元素之后和之前第二个选项有效,但 id 不能以数字开头