判断元素的属性是否存在

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)
}

 

posted @ 2016-05-10 15:20  上官帅帅  阅读(559)  评论(0编辑  收藏  举报