在changePage上发生了两个事件

时间:2013-03-22 18:35:38

标签: jquery xcode cordova jquery-mobile ios6

想象一下,我在页面home.html中,我有一个点击事件到一个元素,它会触发changePageuser.html

好的,home.html中的元素在header中设置,在user.html中,我在相同的html位置中有另一个元素。

问题是:当我点击home.html上的元素时,另一个页面中的另一个vclick事件发生了。只有vclicktap使用click 工作正常才会出现此问题,并且这两个元素需要位于相同的html位置

这是我在home.html中绑定的事件

accessProfile: function(){
    $("body").on("vclick", ".accessUser", function(){
        $.mobile.changePage("user.html");
    });
}

并且这个绑定到user.html

accessHome: function(){
    $("body").on("vclick", ".accessHome", function(){
         $.mobile.changePage("home.html");
    });
}

这只是一个示例,因此,vclickaccessUser,然后changePage发生,但一旦完成,事件.accessHome就会发生并返回主页。同样,只有当两个元素处于相同的html位置时才会发生这种情况。

1 个答案:

答案 0 :(得分:0)

那么,当时我的问题已解决,将所有内容更改为pageinit而不是$(document).ready(function(){...});并使用以下内容阻止多个事件:

 $("body").on("touchstart", ".someElement", function(event){
    if(event.handled !== true){ // This will prevent event triggering more then once
        // code
        event.handled = true;
    }
    return false;
 });