0
我有这个功能更新所有图片:如何更新jQuery中每个函数的特定索引?
setInterval(function(){
console.log($(".image"));
$(".image").each(function(index) {
console.log(index);
base_url = $(this).attr('src').split('?rand=')[0];
address = base_url + '?rand=' + Math.random();
$(this).attr("src", address);
});
},1000);
这在primefaces P用于:graphicImage的:
<ui:repeat value="#{imgController.imgList}" var="images">
<p:graphicImage id="pic" class="image" url="#{images.img}?rand=0" width="360px">
</p:graphicImage>
<p:draggable for="pic" />
</ui:repeat>
我这样做的回报的console.log:
0 image.xhtml?imgId=300335:31
1 image.xhtml?imgId=300335:31
2 image.xhtml?imgId=300335:31
3 image.xhtml?imgId=300335:31
这就是我的疑问,如果我想改为更新所有图像,有没有办法通过一个特定的索引:
each(function(index)
例子:
each(function(3)
如果我只是想更新第三图像?
I'm收到此错误类型错误:img.attr不是一个函数 –
@EdsonCezar - 如果jQuery是正确的'$'安装,你不应该得到这个错误。你可以看到它在我添加到我的答案中的代码片段中工作。 – jfriend00