判断元素的属性是否存在
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) }