Javascript 如何使用jquery从元素中获取属性?
这是我的Javascript 如何使用jquery从元素中获取属性?,javascript,jquery,json,checkbox,key-value,Javascript,Jquery,Json,Checkbox,Key Value,这是我的 有什么想法吗?要获取元素的属性,可以使用$(el).attr('class') 但要在上述情况下获得所需的输出,您可以使用 $('.status').on("click", function () { var array = $('#test').find('input').map(function(idx, el){ return {id: el.id, value: el.value} }).get(); console.log(JSON.s
有什么想法吗?要获取元素的属性,可以使用
$(el).attr('class')
但要在上述情况下获得所需的输出,您可以使用
$('.status').on("click", function () {
var array = $('#test').find('input').map(function(idx, el){
return {id: el.id, value: el.value}
}).get();
console.log(JSON.stringify(array));
});
演示:
}))
使用jquery获取属性ID(和其他属性)以及单选按钮的值
[{
id: id1,
value: value1
} {
id: id2,
value: value2
}]
...
$('.status').on("click", function () {
var array = $('#test').find('input').map(function(idx, el){
return {id: el.id, value: el.value}
}).get();
console.log(JSON.stringify(array));
});
$('.status').on("click", function () {
var radioid = $(this).attr('id'); //gets the attribute ID of the clicked `.status`
radioval = $(this).val(); //gets the value of of the clicked `.status`
alert('ID = ' + radioid + ' and VALUE = ' + radioval); //see the magic
var inputs = $('#test').find('input');
$.each(inputs, function (i, v) {
console.log(v);
});