Javascript 通过单击获取特定div中的所有选中复选框
我有一个自定义asp.net控件,其中包含一些复选框。我知道如何获取已单击的复选框Javascript 通过单击获取特定div中的所有选中复选框,javascript,jquery,Javascript,Jquery,我有一个自定义asp.net控件,其中包含一些复选框。我知道如何获取已单击的复选框 $('#customer-category-control input:checkbox').click(function(event) { var el = $(this).attr('name'); }; 请建议我如何通过单击仅获取所有选中的复选框,并根据其名称创建JSON对象。尝试以下操作: var obj = []; $('#customer-category-control inpu
$('#customer-category-control input:checkbox').click(function(event)
{
var el = $(this).attr('name');
};
请建议我如何通过单击仅获取所有选中的复选框,并根据其名称创建JSON对象。尝试以下操作:
var obj = [];
$('#customer-category-control input[type=checkbox]:checked').each(function(index, value) {
obj.push($(this).attr("name"));
});
试试这个:
var obj = [];
$('#customer-category-control input[type=checkbox]:checked').each(function(index, value) {
obj.push($(this).attr("name"));
});
隐马尔可夫模型。。。我看到各种各样的事件在不同的因素上混杂在一起。为什么要侦听复选框上的单击事件?首先附加一个更改事件,当您要捕获提交事件时,您可以得到一个带有$'customer-category-control input:checkbox:checked'的复选框列表。嗯。。。我看到各种各样的事件在不同的因素上混杂在一起。为什么要侦听复选框上的单击事件?首先附加一个更改事件,当您要捕获提交事件时,您可以获得一个带有$'customer-category-control input:checkbox:checked'的复选框列表。您想单击哪里?你还没有提到你想点击哪里?你没提过吗
$(document).ready(function ()
{
$('#customer-category-control input:checkbox').click(function(event)
{
var obj = [];
$('#customer-category-control input[type=checkbox]:checked').each(function(index, value)
{ obj.push($(this).attr("name")); });
alert(obj);
});
});