开发者

Jquery preventDefault() misbehaves

preventDefault() messes up the events I can handle on one specific page. All I am trying to do is display a static progress bar. Inside the header div I've got links to other html documents and I want them loaded up and then displayed.

I am using this piece of jquery :

$("#header a").click(function(e){
    $('body').append('<div id="progress">Loading...</div>');
    e.preventDefault();
    loadPage(e.target.href);
    e.stopPropagation();
    $('#progress').remove();
});

The problem is that, on the page that is loaded after clicking a link inside the header div, no other click eve开发者_如何学Pythonnt works on that page except the ones in the header. Firebug doesn't even catches clicks anymore outside the header.

Thank you! Stefan


Can you try below code as return false will do both ...preventDefault and stoppropagation

("#header a").click(function(e){
    $('body').append('<div id="progress">Loading...</div>');    
    loadPage(e.target.href);
    $('#progress').remove();
    return false;
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜