0
想要查找内容中的所有标题标签,并检查每个标签有id属性,如果没有,然后添加id属性使用jquery
找到所有标题标签,并检查每个标签有id属性,如果没有添加id属性使用jquery
下面是我的代码:
var headings = $("#edited_content").find("h1,h2,h3,h4,h5,h6");
$.each(headings, function (i, heading) {
attributes = heading.attributes
$.each(attributes, function (j, value) {
if (value.name == 'id') {
alert("id present");
} else {
alert("id absent");
$(this).attr('id', i);
}
});
});
使用的编号为ID是不是在大多数浏览器相当有效。 – gdoron
@gdoron在html5中是有效的....但在CSS中它不会工作....任何方式,我们可以很容易地添加一个前缀到编号 –
非常感谢。它的工作是我期望的。 – user2138489