jQuery click function work but live click not work

左心房为你撑大大i 提交于 2019-12-12 01:40:48

问题


i am trying to run a live click function in jQuery and found that's not work like

$(function () {
    $("#elem #check").click(function () {
        alert('goaa');
    });
    $("#elem #check").live("click", function () {
        alert('fo');
    });

});

the page load and nothing come from ajax.when i trying to run that i found that [click] first is work and second not [live click].

what is the reason of click are work and live not worked.:-

Well it is my fault that i am trying to run it on jQuery UI tab so that's not worked.


回答1:


No idea what the problem is. As you can see in the following live demonstration this code works perfectly fine.




回答2:


probably somewhere for your selector or on parent elements click event stopped for ex $("#elem") or on parent

$("#check").live("click", function (event) {
        event.stopPropagiation();
    });

in oter place stopped event bubbling and capture




回答3:


Earlier, live function works perfectly in a dynamic loaded content. But it is not working on recent JQuery file. But you can use another function: https://api.jquery.com/delegate/



来源:https://stackoverflow.com/questions/4913636/jquery-click-function-work-but-live-click-not-work

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!