Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jquery-ui/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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/lua/3.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 ui 动态生成HTML时,如何将jquery附加到click()事件?_Jquery Ui - Fatal编程技术网

Jquery ui 动态生成HTML时,如何将jquery附加到click()事件?

Jquery ui 动态生成HTML时,如何将jquery附加到click()事件?,jquery-ui,Jquery Ui,我使用JQUeryUI向最终用户显示一个对话框,并用动态生成的HTML填充它,如下所示 $('#listusers').click(function() { $("#dialog").html(""); $("#dialog").attr("title", "Existing Users"); $("#dialog").load("service/get.aspx?data=users", $(function(data) { $("#dialog").dialog({

我使用JQUeryUI向最终用户显示一个对话框,并用动态生成的HTML填充它,如下所示

$('#listusers').click(function() {
    $("#dialog").html("");
    $("#dialog").attr("title", "Existing Users");
    $("#dialog").load("service/get.aspx?data=users", $(function(data) { $("#dialog").dialog({ modal: true }); }));
});
<div class="ui-widget" id="users-contain">
    <h1>Existing Users:</h1>
<table class="ui-widget ui-widget-content" id="users">
    <thead>
        <tr class="ui-widget-header">
            <th>Act</th>
            <th>Name</th>
            <th>Email</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>
                <a href="#" class="deleteuser" id="0delete">
                    <img src="images/49.gif" alt="help">
                </a>
            </td>
            <td id="0username">JoePlumber</td>
            <td>joe@mcain2008.org</td>
        </tr>
        <tr>
            <td>
                <a href="#" class="deleteuser" id="1delete">
                    <img src="images/49.gif" alt="help">
                </a>
            </td>
            <td id="1username">SarahPalin</td>
            <td>sarah@cliffnotes.com</td>
            </tr>
    </tbody>
</table>
</div>
从“service/get.aspx?data=users”返回的HTML如下所示

$('#listusers').click(function() {
    $("#dialog").html("");
    $("#dialog").attr("title", "Existing Users");
    $("#dialog").load("service/get.aspx?data=users", $(function(data) { $("#dialog").dialog({ modal: true }); }));
});
<div class="ui-widget" id="users-contain">
    <h1>Existing Users:</h1>
<table class="ui-widget ui-widget-content" id="users">
    <thead>
        <tr class="ui-widget-header">
            <th>Act</th>
            <th>Name</th>
            <th>Email</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>
                <a href="#" class="deleteuser" id="0delete">
                    <img src="images/49.gif" alt="help">
                </a>
            </td>
            <td id="0username">JoePlumber</td>
            <td>joe@mcain2008.org</td>
        </tr>
        <tr>
            <td>
                <a href="#" class="deleteuser" id="1delete">
                    <img src="images/49.gif" alt="help">
                </a>
            </td>
            <td id="1username">SarahPalin</td>
            <td>sarah@cliffnotes.com</td>
            </tr>
    </tbody>
</table>
</div>
我应该把代码放在哪里

我试过了,但是没有成功

$('#delete-user').click(function() {
    $("#dialog").html("");
    $("#dialog").attr("title", "Existing Users");
    $("#dialog").load("service/get.aspx?data=users", $(function(data) { $("#dialog").dialog({ modal: true }); }));
    $(".deleteuser").click(function() {
        alert('help');
    });
});

在main document.ready函数中,添加以下内容:

$(".deleteuser").live('click',function() {
        alert('help');
    });  
live()将事件绑定到选择器的所有事件,包括在函数调用时不存在的事件,这意味着通过ajax调用的所有元素。

在主document.ready函数中,添加以下内容:

$(".deleteuser").live('click',function() {
        alert('help');
    });  
live()将事件绑定到选择器的所有事件,包括在函数调用时不存在的事件,这意味着通过ajax调用的所有元素。 使用活绑定-


$(“.delete user”).live(“单击”,函数(evt){
[做事]
);

使用实时绑定-


$(“.delete user”).live(“单击”,函数(evt){
[做事]
);