爲什麼我的imageIndex保持返回-1;jquery index()返回-1
$(function(){
//rotateImages();
setInterval("rotateImages()", 4000);
});
var imageIndex = 0;
var currentPhoto = $("#photoShow div.current");
function rotateImages(){
var max = $("#photoShow div").length;
imageIndex = currentPhoto.index();
console.log(imageIndex + " :: "+ (max - 1));
}
HTML:
<body>
<div id="photoShow">
<div class="current">
<img src="images/Grass.jpg" alt="Photo Gallery" width="400" height="400" class="gallery" />
</div>
<div>
<img src="images/Leaf.jpg" alt="Photo Gallery" width="400" height="400" class="gallery" />
</div>
<div>
<img src="images/Spring.jpg" alt="Photo Gallery" width="400" height="400" class="gallery" />
</div>
<div>
<img src="images/Water.jpg" alt="Photo Gallery" width="400" height="400" class="gallery" />
</div>
</div>
[返回'0對我來說](http://jsfiddle.net/Marcel/v7LAb/show),這是正確的。 – Marcel 2011-05-20 04:30:47