开发者

Jquery mobile multiple click events when go back into page

I have just upgraded jquery mobile to beta 2(from beta 1) and I am now receiving multiple click events if i go back into a page after pressing back, each time I go back in it adds another to the click so th开发者_开发知识库e alert fires however many times you go into the page

I have also noticed that clicks/taps seem to go through the current page and clicking on pages hidden by view - seems really strange but I am thinking they are probably linked.

It is as if it is creating multiple versions of the same page and when you go back into it loads a new one causing there to be two click events.

Here is a snippet of the code which is being fired

$('#click_me').live('vclick', function() {
    alert('clicked');
});

Hopefully this makes sense and anyone can shed any light on what might be going on?


You've probably solved this by now, but you need to use the pagecreate event. @Phill's suggestion of:

$('div').live('pageshow',function(event, ui){
    $('#click_me').click(function() {
        alert('clicked');
    });
});

Unfortunately won't help, but you can solve the issue if you change pageshow to pagecreate

$('div').live('pagecreate',function(){
    $('#click_me').click(function() {
        alert('clicked');
    });
});

If you're not using AJAX to load your pages, make sure also to change live to bind.

I had this same issue myself and this has solved it completely for me.


UPDATED:

I think the reason is you have the click event tied to the live event, so evrytime you navigate to that page it triggers the click event. try something like this:

$('div').live('pageshow',function(event, ui){
    $('#click_me').click(function() {
        alert('clicked');
    });
});

or just use the click event

$('#click_me').click(function() {
    alert('clicked');
});

When Beta 2 was released they are deprecating vclick

  • http://jquerymobile.com/blog/2011/08/03/jquery-mobile-beta-2-released/

Backtrack: We’ve switched back from vclick to click for links

In Beta 1, we decided to use our custom vclick event for handling Ajax links to improve responsiveness and to hide the URL bar on the iPhone and Android phones. Even though we did quite a bit of testing before landing this for Beta 1, we began to hear feedback that this change was causing some significant issues out in the wild including:

  • Multiple click events causing navigation and form element issue – In certain situations, when tapping an element, tap/click events seem to fire twice on links and is due to edge cases where the target of the touch event and mouse event don’t match due to how the browsers calculate tolerances for these events. This is most pronounced on Android 2.1, but affected most WebKit-based browsers to varying degrees when a tap events occured near the edge of an element.

  • Click handlers in custom scripts didn’t “work” anymore – if a script bound only to click events on the document, the global vclick feature could interfere because the touch events may supercede click events so it events wouldn’t appear to trigger.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜