判断元素的属性是否存在

function getSections() {
//var sections = "";
//var spanSections = $("#orgname tr td").find("span");
//for (var i = 0; i < spanSections.length; i++) {
// if ($(spanSections[i]).attr("data-sections") != null) {
// sections += $(spanSections[i]).attr("data-sections") + ","
// }
//}
//return sections.substring(0, sections.length - 1)
var sections = "";
var spanSections = $("#orgname tr td").find("span")
spanSections.each(function () {
if ($(this).attr("data-sections") != null) { //当前元素的data-secions 属性是否存在
sections += $(this).attr("data-sections") + ","
}
})
return sections.substring(0, sections.length - 1)
}
原文地址:https://www.cnblogs.com/keno32/p/5477957.html