开发者

jquery mobile tap problem if pressed more than once

All I want is to Refresh the page and pass a parameter back to my index controller, but Slide up the page.

If I press once, no problem. If I keep pressing Refresh then it literally doubles the call each time I press it. So if I press 3 times it calls the index view @ 4 times

$(document).ready(function(){
    $(".ui-btn-right").bind('tap vclick',function(event, ui){
        event.preventDefault();
    //  alert("saw tap");
        $开发者_运维问答.mobile.changePage( "/app/Person/index?refresh_view=true", { transition: "slideup", reloadPage: true} );
     });

});

And link is:

<a class="ui-btn-right" data-theme="b" href="/app/Person/index?refresh_view=true" data-transition="slideup">Refresh</a>


jQuery mobile is unique in that when the page changes, none of the elements in the DOM are removed. Since no elements are removed, their events stay there too. I'm guessing that your $(document).ready( ... ) function is getting called at every new page. So you're adding a new event to the .ui-btn-right element even though the other ones are still there. Try this:

$(document).ready(function(){
    $(".ui-btn-right").bind('tap vclick',function(event, ui){
        event.preventDefault();
    //  alert("saw tap");
        $('ui-btn-right').unbind('tap vclick');
        $.mobile.changePage( "/app/Person/index?refresh_view=true", { transition: "slideup", reloadPage: true} );
     });

});

Now, whenever you change pages, the event is removed so there aren't any duplicates when the $(document).ready( ... ) function is called again.


There was an issue with Beta 1 and vclick, they have fixed the issue in Beta 2:

  • http://jquerymobile.com/demos/1.0b2/

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜