如何使用click()处理javascript动态创建的项目?

时间:2017-04-18 14:00:55

标签: javascript php html

我目前正在试图弄清楚为什么click()不能用于使用js动态创建的按钮。以下是我的代码:

       jQuery(document).ready(function()
            {

                jQuery.ajax({
                url:ajaxobject.ajaxurl,
                method: 'GET',
                data: {
                    action: '2017_application'
                },
                success: function(data)
                {
                    var applications = JSON.parse(data);

                    for (var i = 0; i < applications.length; i++)
                    {
                        var content = '<div class = "app2-row app2-data">' +

                                            '<div class = "app2-col" style="font-weight:bold;">' + applications[i]['teamname'] + '</div>'+
                                            '<div class = "app2-col">' + applications[i]['firstname'] + '</div>'+
                                            '<div class = "app2-col">' + applications[i]['lastname'] + '</div>'+
                                            '<div class = "app2-col"style="font-weight:bold;">' + applications[i]['status'] + '</div>'+

                                            '<div class = "app2-col">' +
                                                '<button onclick="window.location.href=\'/info/?teamname='+ applications[i]['teamname'] + '\'">View</button><br>' +
                                                '<button class = "app2-accept" tname='+applications[i]['teamname']+'>Accept</button><br>' +
                                                '<button class = "app2-remove">Remove</button><br>' +
                                            '</div>'+
                                        '</div>';

                        jQuery("#app2-table").append(content);
                    }
                }
            });

当我在&#34; .app2-accept&#34;上使用click()时没有任何反应。

    jQuery(".app2-accept").click(function()

                alert("Testing");

         });

有人可以建议如何解决这个问题吗?

0 个答案:

没有答案