[英]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.