单击不使用复选框标记的事件

Click event not working with the checkbox tag

本文关键字:事件 复选框 单击      更新时间:2023-09-26

我有下面的代码:

        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标记进行更改将起作用,但我需要使用checkbox类。

我们非常感谢您的每一次帮助。

使用EventDelegation:

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

来自文档:

事件委派允许我们将单个事件侦听器附加到父元素,将为匹配选择器,无论这些子体现在存在还是添加到将来