【发布时间】:2011-06-15 11:21:00
【问题描述】:
所以我可以将所有我想要的图像放入一个数组并将它们传递给 $image。但是,当我尝试遍历该数组时,它只会不断提醒同一个项目 3 次。
我遇到问题的代码。
getItem : function($image){
console.log($image)
console.log(jQuery.type($image))
var setup ='<img src="' + $($image).attr('href') + '" title="' + $($image).attr('title') + '"/>';
$.each($image, function(i){
alert( setup);
});
}
HTML
<a href="images/slideshow/1-GW.PhillipBarnhart.ReverendMemory.jpg" title="Phillip Barnhart as:
Reverend Memory - a clergyman who stands for decorum and truth." rel="slideshow"><img src="images/view-slideshow.jpg" width="490" height="352" alt="View Slideshow"></a>
<a rel="slideshow" href="images/slideshow/2-GW.BethBrooks.POLLYTODD.jpg">fff</a>
<a rel="slideshow" href="images/slideshow/3-GW.NickHale.NOSTALGIA.jpg">test</a>
整个脚本或者如果你喜欢 jsFiddle 这里是一个链接。 http://jsfiddle.net/h3az4/
var slideShow = {
config : {
wrapper : 'body',
container : 'div',
anchor : 'a[rel="slideshow"]'
},
init : function(config) {
$.extend(slideShow.config, config);
$(slideShow.config.anchor).hide();
$(slideShow.config.wrapper).find(slideShow.config.anchor)
.eq(0)
.show()
.click(function(e){
e.preventDefault();
slideShow.getItem($(slideShow.config.anchor));
});
},
getItem : function($image){
console.log($image)
console.log(jQuery.type($image))
var setup ='<img src="' + $($image).attr('href') + '" title="' + $($image).attr('title') + '"/>';
$.each($image, function(i){
alert( setup);
});
},
createTumbnail : function($image){
}
};
$(document).ready(function() {
slideShow.init();
});
【问题讨论】:
-
我认为您的
var setup需要在$.each循环中声明。
标签: javascript jquery iterator