Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jsf-2/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery JavaScript onclick事件失败_Jquery_Html Table - Fatal编程技术网

Jquery JavaScript onclick事件失败

Jquery JavaScript onclick事件失败,jquery,html-table,Jquery,Html Table,我用append生成html,然后 我试图简单地提醒点击按钮,但失败了 追加之前我的JavaScript 附加后的HTML 您必须为按钮绑定单击事件:- $("#sendMailBtn").click(function() { alert("Handler for .click() called."); }); 因此,您的代码基本上应该如下所示:- $(document).ready(function() { $("#sendMailBtn").click(fu

我用append生成html,然后 我试图简单地提醒点击按钮,但失败了

追加之前我的JavaScript

附加后的HTML


您必须为按钮绑定单击事件:-

 $("#sendMailBtn").click(function() {
      alert("Handler for .click() called.");
    });
因此,您的代码基本上应该如下所示:-

$(document).ready(function() {

    $("#sendMailBtn").click(function() {
      alert("Handler for .click() called.");
    });

    $('#selUsersToSendMail').click(function(){
                var selUsersArray = [];

                $(".tableBodyConfirmUser1").html('');

                $(".selUsersClass:checked").each(function () {
                    var ids = $(this).attr('value');
                    $(".tableBodyConfirmUser1").append("<tr id='subsUserId_"+ids+"' class='subsUserId_"+ids+"'>"+$("#selUserId_"+ids).html()+"</tr>");

                    selUsersArray.push(ids);            
                });

                $(".tableBodyConfirmUser1").append("<tr><td valign='top' colspan='3'><input type='button' style='width:50px;' name='sendMailBtn' id='sendMailBtn' class='sendMailBtn' value='Select'/></td></tr>");

            });

});
检查更新的

注意:-我已经从HTML中删除了testFunction

换行

$(".tableBodyConfirmUser1").append("<tr><td valign='top' colspan='3'><input type='button' style='width:50px;' name='sendMailBtn' id='sendMailBtn' class='sendMailBtn' value='Select' onclick='testFunction();'/></td></tr>");

我试着在某某身上找到答案,也试着从某某身上找到答案。。但在我遇到同样的问题后。它正在工作,请检查我为您创建的小提琴。在mozilla和chromethakx bhai中测试。。。但我需要在append之后运行事件,这意味着为即将到来的dom元素委派事件处理程序。。thnakx for ur supportokay..那么您需要从append中删除onclick事件,因为您之前已经绑定了click事件。
$(document).ready(function() {

    $("#sendMailBtn").click(function() {
      alert("Handler for .click() called.");
    });

    $('#selUsersToSendMail').click(function(){
                var selUsersArray = [];

                $(".tableBodyConfirmUser1").html('');

                $(".selUsersClass:checked").each(function () {
                    var ids = $(this).attr('value');
                    $(".tableBodyConfirmUser1").append("<tr id='subsUserId_"+ids+"' class='subsUserId_"+ids+"'>"+$("#selUserId_"+ids).html()+"</tr>");

                    selUsersArray.push(ids);            
                });

                $(".tableBodyConfirmUser1").append("<tr><td valign='top' colspan='3'><input type='button' style='width:50px;' name='sendMailBtn' id='sendMailBtn' class='sendMailBtn' value='Select'/></td></tr>");

            });

});
$(".tableBodyConfirmUser1").append("<tr><td valign='top' colspan='3'><input type='button' style='width:50px;' name='sendMailBtn' id='sendMailBtn' class='sendMailBtn' value='Select' onclick='testFunction();'/></td></tr>");
$(".tableBodyConfirmUser1").append("<tr><td valign='top' colspan='3'><input type='button' style='width:50px;' name='sendMailBtn' id='sendMailBtn' class='sendMailBtn' value='Select'/></td></tr>");
$(document).ready(function() {

     // delegate event handler for upcoming dom element
     // aka live event

     $('.tableBodyConfirmUser1').on('click', '#sendMailBtn', function() {
        alert('Button clicked');
     });

     // your code
});