簡體   English   中英

點擊事件不適用於復選框標簽

[英]Click event not working with the checkbox tag

我在下面的代碼:

        html.push('<tr class="reservas">');
        html.push('<td> <input type="checkbox" class="checkbox" data-name="' + bla.name + '" data-email="' + bla.email /> </td>'); // atribui os dados a atributos para serem acessados posteriormente por jquery.
        html.push('<td>' + bla.name + '</td>');
        html.push('<td>' + bla.email + '</td>');
        html.push('</tr>');
        $('tbody').append(html.join(""));


$(function(){
    $('.save').on('click', function(){
   });
});

click事件不起作用,如果我更改body標記將起作用,但是我需要使用復選框類。

非常感謝您的幫助。

使用EventDelegation:

$(function(){
    $(document).on('click', '.checkbox', function(){
        alert('salvo');
   });
});

從文檔中:

通過事件委托,我們可以將單個事件偵聽器附加到父元素,該元素將為與選擇器匹配的所有后代觸發,無論這些后代現在存在還是將來添加。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM