使用iscroll时Onclick事件触发两次

时间:2014-03-12 08:06:48

标签: jquery events scroll phonegap-plugins iscroll4

我正在使用嵌套的iscroll4,但

  • 上的onclick事件会触发两次。 首先添加了一个div,仅用于使用iscroll进行滑动,其li位于: -

         <li>     
               <div class="pullContainer">
                <div class="wraps" id="w1">
                  <div class="scrolls" id="sc1">
                    <div id="pullDown1" class="pullDowns">
                     <span class="pullDownIcon"></span>
                       <span class="pullDownLabel1">Pull down to refresh...</span>
                     </div>
                     <div class="scrollContainer" id="nearBy"></div>
                       <!-- Template  container -->
                     <script id="myTemplate" type="text/x-jquery-tmpl">
                      {{if (data.length > 0)}}
                     <ul class = "forSmooth" id="nearbyList">
                      {{each data}}
                      <li class = "smooth" data-businessId = "${$value.id}" data-distance = "${$value.distance}" data-prev-page ="homePage" onclick = "alert('hi');">
    

    警报在这里发射两次......那么我怎样才能通过第二次射击来防止这种情况发生。

  • 1 个答案:

    答案 0 :(得分:1)

    试试这个:

    <li class = "smooth" data-businessId = "${$value.id}" data-distance = "${$value.distance}" data-prev-page ="homePage" onclick = "AlertFunction()";">
    
    function AlertFunction(e){
        alert("Hi");
        e.stopPropagation();
    }
    

    注意:完全未经测试的代码