admin管理员组文章数量:1391008
I have checkboxes on a page and I get the checked ones then I loop through them;
var checkeds = $('#accTypes input:checked');
var values = "";
for (var i = 0; i < checkeds.length; i++) {
console.log(checkeds[i]);
var cval = checkeds[i].val();
values = values + "," + cval;
}
I recognized that the row below causes error.
checkeds[i].val()
When I print the checkeds[i] variable in chrome console, I see;
<input type="checkbox" name="ac-check" id="checkboxP12" value="12">
I wanted to get the value of checkeds[i] variable. How can I do this?
I have checkboxes on a page and I get the checked ones then I loop through them;
var checkeds = $('#accTypes input:checked');
var values = "";
for (var i = 0; i < checkeds.length; i++) {
console.log(checkeds[i]);
var cval = checkeds[i].val();
values = values + "," + cval;
}
I recognized that the row below causes error.
checkeds[i].val()
When I print the checkeds[i] variable in chrome console, I see;
<input type="checkbox" name="ac-check" id="checkboxP12" value="12">
I wanted to get the value of checkeds[i] variable. How can I do this?
Share Improve this question asked Sep 7, 2014 at 11:42 Serhat KorogluSerhat Koroglu 1,2754 gold badges19 silver badges42 bronze badges1 Answer
Reset to default 4A jQuery collection is an array-like object containing native DOM nodes.
When you access it as checkeds[1]
you get the native DOM node, not the jQuery version, so it doesn't have a val()
method.
Either use the native value
var cval = checkeds[i].value;
or use eq()
to get the jQuery object
var cval = checkeds.eq(i).val();
As a sidenote, you could do the same thing with a map
var values = $('#accTypes input:checked').map(function() {
return this.value;
}).get().join(',');
本文标签: javascriptGetting value of a quotobject HTMLInputElementquot and function errorStack Overflow
版权声明:本文标题:javascript - Getting value of a "object HTMLInputElement" and function error - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744609922a2615593.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论