我有一系列的水平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