gpt4 book ai didi

javascript - 如何从复选框中获取值属性

转载 作者:行者123 更新时间:2023-11-30 09:59:49 24 4
gpt4 key购买 nike

我需要从这里获取每个 checked checkboxvalue 属性:

$("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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com