【发布时间】:2022-08-16 21:18:11
【问题描述】:
无法弄清楚为什么这个循环不会给我我想要的信息
我有一个页面上有几百个输入,我想为每个检查的输入获取输入“名称”值
<input type=\"checkbox\" name=\"TAXI_SQUAD0001\" checked=\"checked\">
<input type=\"checkbox\" name=\"TAXI_SQUAD0021\" checked=\"checked\">
<input type=\"checkbox\" name=\"TAXI_SQUAD0011\">
$.ajax({
url: urlHPM,
xhrFields: {
withCredentials: true
},
cache: false,
type: \"GET\",
success: function (data) {
checkedInputs = $(data).find(\'input[checked=\"checked\"]\');
for (var i = 0; i < checkedInputs.length; i++) {
console.log(checkedInputs.attr(\'name\')[i]); // loops character of first name of first input over and over
console.log(checkedInputs[i].attr(\'name\')); // error attr not a function
// i want to log input names TAXI_SQUAD0001 and TAXISQUAD0021
}
},
error: function (xhr) {
}
});
-
试试
$(checkedInputs[i]).attr(\'name\') -
如果你打算使用 jQuery,你应该使用 jQuery 来做循环。
标签: javascript jquery