Jquery mobile JQM在同一对象上多次注册相同的

Jquery mobile JQM在同一对象上多次注册相同的,jquery-mobile,jquery,Jquery Mobile,Jquery,我正在使用一个多页面模板构建一个测试移动应用程序,但是每次我从主页导航到搜索页面时,JQM都在同一对象上递增地注册相同的事件 如果我在主页上并导航到搜索页面,第一次1 onclick事件附加到UL中我的“li a”,但如果我使用标准JQM返回按钮再次返回主页并再次单击搜索页面,则在UL中的每个“li a”上注册的2个事件完全相同。如果我第三次做的话,会有3次,以此类推 相关搜索页面标记: <div id="searchResults"> <ul id="catResul

我正在使用一个多页面模板构建一个测试移动应用程序,但是每次我从主页导航到搜索页面时,JQM都在同一对象上递增地注册相同的事件

如果我在主页上并导航到搜索页面,第一次1 onclick事件附加到UL中我的“li a”,但如果我使用标准JQM返回按钮再次返回主页并再次单击搜索页面,则在UL中的每个“li a”上注册的2个事件完全相同。如果我第三次做的话,会有3次,以此类推

相关搜索页面标记:

<div id="searchResults">
    <ul id="catResult" class="ui-listview" data-role="listview" data-inset="true" data-theme="c" data-dividertheme="b">
        <li data-role="listdivider" data-theme="b">Search Categories</li>
    </ul>
</div>
调试结果:

点击 [Object{type=“click”,origType=“click”,guid=306,more…},Object{type=“click”,origType=“click”,guid=469,more…},Object{type=“click”,origType=“click”,guid=537,more…}]


每一个都注册在“LIA”上。我认为这与此代码有关。每次导航到搜索页面时,都会将另一个单击事件附加到定位项

下面是要演示的JSFIDLE


该单击事件似乎与pagebeforeshow事件中发生的任何事件无关。只需将事件声明从pagebeforeshow事件声明中取出即可

谢谢你。。。我的工作假设页面的所有事件寄存器都需要包含在页面初始化中。。。我把事件寄存器移到了脚本文件的主体中,现在一切都正常了。。。非常感谢。
$('body').on('pagebeforeshow', '#searchPage', function(event){ // check if page is shown then execute code
    setScrollBar("show");
    buildCategoryList();
    setListMenuHeight(".ui-2col-layout .ui-2column-grid .ui-block-a", wHeight);

   // This event register is being registered multiple times
   $('#catList').on('click', 'li a', function(){
       var href = $(this).attr('href');
       var id = href.split('=');
       console.log('spLoadCategoryResults('+id[1]+')');
       spLoadCategoryResults(id[1]); // return results from database
    });    

    $("[data-rel=back]").click(function(){
                    // removes appended elements from the DOM is they exist
        cleanPage(['#catResult li','#locationMap #mapCanvas','#searchResults #spResult']); 
    });

    // DEBUG - shows how many times the event is registered
    var data = jQuery._data( catList, "events" );
    console.log(data);      

});
0
    Object { type="click", origType="click", guid=306, more...}

1
    Object { type="click", origType="click", guid=469, more...}

2
    Object { type="click", origType="click", guid=537, more...}

delegateCount
    3

remove
    [Object { type="remove", origType="remove", guid=210, more...}]
// This event register is being registered multiple times
 $('#catList').on('click', 'li a', function(){
   var href = $(this).attr('href');
   var id = href.split('=');
   console.log('spLoadCategoryResults('+id[1]+')');
   spLoadCategoryResults(id[1]); // return results from database
});