/**
* 获取...标签的id/name以...开头的集合
* @param tag html标签
* @param prefix 前缀
* @param attr id/name
* @returns {jQuery|HTMLElement}
*/
function getStartLabelArr(tag, prefix, attr) {
if (attr === "id") {
return $(tag + "[id^='" + prefix + "']");
} else if (attr === "name") {
return $(tag + "[name^='" + prefix + "']");
} else {
return null;
}
}
/**
* 获取...标签的id/name以...结尾的集合
* @param tag html标签
* @param suffix 后缀
* @param attr id/name
* @returns {jQuery|HTMLElement}
*/
function getEndLabelArr(tag, suffix, attr) {
if (attr === "id") {
return $(tag + "[id$='" + suffix + "']");
} else if (attr === "name") {
return $(tag + "[name$='" + suffix + "']");
} else {
return null;
}
}
//使用示例1,获取标签的id以trainParticipateTrainingUserList开始的array
var trArr = getStartLabelArr("tr", "trainParticipateTrainingUserList", "id");
console.log(trArr.length);
//使用示例2,获取
var endLabelArr = getEndLabelArr("select", "_user_id", "id");
console.log(endLabelArr.length);
你可能感兴趣的:(JavaScript,jQuery,HTML,JavaScript,jQuery,HTML)