作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我需要从这里获取每个 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/
我是一名优秀的程序员,十分优秀!