[英]Dynamically created checkbox click detect with no class or id Jquery
我有一些类似下面的复选框,它们是动态创建的。
<input type="checkbox" name="feature[]" value="9">
如您所见, 没有id或class 。 并且name属性是类型数组。 现在,我无法在这些复选框上检测到检查事件。 我需要检测事件,并同时检测事件发生的值。
我已经检查了几个与此相关的示例,但通常它们都使用了类或id或name 。但是在这些示例中,name不在数组类型中。 我已经尝试过使用name属性,但是无法管理。 请帮忙.......
你可以试试这个
$("input[name^='feature']").click(function(){
alert($(this).val());
});
使用属性等于选择器
$(document).on('change', 'input[name="feature[]"]', function(){
//do something
})
<input type="text" name="feature" value="123" />
$("input").click(function(){
var txt = $(this).val();
alert(txt);
alert($(this).attr("name"));
});
Try this once
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.