我需要从这里获取每个 checked checkbox
的 value
属性:
$("input:checkbox[name=marca-chk]:checked").each(function(){
bufferTmp.push($(this).prop('value'));
});
但是使用 .prop('value')
我得到了 "is checked"
value 有什么办法可以解决这个问题吗?
提前谢谢你。
最佳答案
来自 Op 的评论:
问题不在于 prop()
,但是你的 <input>
元素没有属性 value
.
<input type="checkbox" name='marca-chk' val="on">marca-chk1
// ^^^
因此,您无法获取名称 value
的属性,那就是 undefined
.
原始答案(已过时)
使用 val()
而不是 prop()
获取复选框的值
Get the current value of the first element in the set of matched elements.
$(this).val()
代码
$("input:checkbox[name=marca-chk]:checked").each(function() {
bufferTmp.push($(this).val());
// ^^^^^^
});
关于javascript - 如何从复选框中获取值属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32267389/