Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/82.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.ajax新元素检查_Jquery_Ajax_Login_Refresh_Element - Fatal编程技术网

jQuery.ajax新元素检查

jQuery.ajax新元素检查,jquery,ajax,login,refresh,element,Jquery,Ajax,Login,Refresh,Element,我正在尝试使用ajax登录网页。我有这个: $.ajax({ type: "POST", url: "ajax/login.php", data: dataString, success: function(answer) { $('#loging').html(answer); } }); 它工作得很好,但是:在答案中,变

我正在尝试使用ajax登录网页。我有这个:

    $.ajax({
       type: "POST",
       url: "ajax/login.php",
       data: dataString,               
       success: function(answer) {
           $('#loging').html(answer);           
       }      
    });
它工作得很好,但是:在答案中,变量是这样的:

    Hi user, <span id="logout_button">Logout</span>
Hi用户,注销
我可以看到“注销”按钮,但我的浏览器不知道这里有任何span id=“注销”按钮”。我用#logout#按钮绑定了注销代码,但它不起作用,因为我的浏览器对这个按钮一无所知。当我刷新页面时,注销工作正常

那么,有没有任何方法/函数可以对jQuery说“嗨,伙计,请检查文档中的新元素”?

是的,您可以使用.delegate()而不是.bind()

是的,您可以使用.delegate()而不是.bind()


对于jQuery1.7+来说,最好使用“on”


对于jQuery1.7+来说,最好使用“on”

请定义“工作良好”和“不起作用”请定义“工作良好”和“不起作用”
$('body').delegate('#logout_button', 'click', function() {
    //here the code
});
$("body").on("click", "#logout_button", function() {
    //here the code
});