누락 된 내용이있을 것입니다. 요소의 인덱스를 얻으려고하지만 -1을 계속 얻으려고합니다.jQuery 색인 문제()
HTML :
<div id="rating_boxes">
<img src="/img/ratingbox.gif" class="ratingbox" alt="Rate this Speech" />
<img src="/img/ratingbox.gif" class="ratingbox" alt="Rate this Speech" />
<img src="/img/ratingbox.gif" class="ratingbox" alt="Rate this Speech" />
<img src="/img/ratingbox.gif" class="ratingbox" alt="Rate this Speech" />
<img src="/img/ratingbox.gif" class="ratingbox" alt="Rate this Speech" />
<img src="/img/ratingbox.gif" class="ratingbox" alt="Rate this Speech" />
<img src="/img/ratingbox.gif" class="ratingbox" alt="Rate this Speech" />
<img src="/img/ratingbox.gif" class="ratingbox" alt="Rate this Speech" />
<img src="/img/ratingbox.gif" class="ratingbox" alt="Rate this Speech" />
<img src="/img/ratingbox.gif" class="ratingbox" alt="Rate this Speech" />
</div>
jQuery를 :
$("img.ratingbox").hover(function() {
var index = $(this).parent().index(this);
// have also tried $("#rating_boxes").index(this);
// and $("#rating_boxes").index($(this));
// and $(this).parent().index($(this));
alert(index);
$(this).attr('src', '/img/ratingbox-selected.gif');
}, function() {
$(this).attr('src', '/img/ratingbox.gif');
});
만약 내가 할 수 있으면 20 회 upvote 것이다. .index()는 의미가 없습니다. – nipponese
큰 접근! – Alexander