$("[data-musterfull]:visible").each(function(){
var bild = $(this).data('musterfull'); // fine till here
$(this).attr('src', data); // this isn't working
});
如何修复不工作的部分?
问题是因为您定义了名为 的变量bild
,而不是data
.
另请注意,您可以通过向 提供函数来使逻辑更加简洁attr()
,如下所示:
$("[data-musterfull]:visible").attr('src', function() {
return $(this).data('musterfull');
});
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句