1
我写这个代码,它不工作jQuery的使用变量
$('.item').each(function(){
var ItemGradient1 = $(this).attr('data-gradient-1');
var ItemGradient2 = $(this).attr('data-gradient-2');
var ItemGradient = 'linear-gradient(to right bottom, ' + ItemGradient1 + ', ' + ItemGradient2 + ');'
$(this).children('.portfolio-wrapper').append('<div class="item-after"></div>');
$(this).children('.portfolio-wrapper').children('.item-after').css('background', ItemGradient);
console.log(ItemGradient);
});
我认为这doenst因为该行的工作:
$(this).children('.portfolio-wrapper').children('.item-after').css('background', ItemGradient);
这是HTML:
<div class="item Others" data-cat="Others" data-path="/portfolio/others/jonasplatin_website/" data-gradient-1="#ffef80" data-gradient-2="#464646">
<div class="portfolio-wrapper">
<img src="/portfolio/others/jonasplatin_website/thumbnail.jpg" alt="Jonas Platin unofficial website" />
<div class="desc">
<h2 class="item-info">Jonas Platin unofficial website</h2>
<h3 class="item-info">Webdesign</h3>
</div>
</div>
</div>
您是否看到错误?感谢您的帮助
我认为这将是一个好主意,也显示HTML结构 –
这是什么应该做的?你突出显示的那条线让你认为这是问题所在? –