我有一系列的水平div盒,我需要添加相關的href鏈接到下一個與anchorlinks。由於它們是動態生成的,我需要在JavaScript中添加href。動態添加href到鏈接
的預期效果將是:
<div id="post1">
<a class="next-video" href="#post2">NextVideo</a>
</div>
<div id="post2">
<a class="next-video" href="#post3">NextVideo</a>
</div>
添加腳本
$('.next-video').each(function(index) {
$(this).attr('href', '#post' + (index + 2));
});
,但似乎並沒有針對.next-video
類,這是真人版: http://www.warface.co.uk/clients/detail-shoppe/test-scroll
非常感謝
你有很多'ID =頁面中的「wrapper」和「id =」post2「'元素,以及其他問題:http://validator.w3.org/check?uri=http://www.warface.co.uk/clients/detail -shoppe/test-scroll&charset =(detect + automatically)&doctype = Inline&group = 0你應該修正這些...在頁面加載後運行腳本運行正常,看看修復無效標記是否有助於它正確運行'document.ready '。 – 2010-08-22 11:50:20
嗚嗚,感謝尼克的標記建議,並且效果很棒:) – Rob 2010-08-22 11:59:37