我得到了这个脚本:
JS
$("#content div.nav").each(function() {
$(".navi ul").append('<li><a href="#'+ $(this).attr("id") + '">' + $(this).attr("id") + '</a></li>');
});它产生的ID是一个导航,但有时我有一个ID与一个空格,例如"Agen da“和这样一个anker脚本不滚动,你能帮我吗?
小提琴
http://jsfiddle.net/RDFf9/14/
发布于 2014-04-25 08:23:02
让我们让它与空格一起工作:)
创建这样的div:
<div title="Location 3" id="Location3" class="nav">删除id中的空格,然后添加可以有空格的title属性。
然后把你的剧本写成这样:
$("#content div.nav").each(function() {
$(".navi ul").append('<li><a href="#'+ $(this).attr("id") + '">' + $(this).attr("title") + '</a></li>');
});注意,我将第二个id替换为title。
检查演示这里
希望它能帮上忙
发布于 2014-04-25 08:05:25
HTML元素ID不能有空格。
https://stackoverflow.com/questions/23287458
复制相似问题