同一页面中的多次交换不起作用

时间:2013-11-05 08:18:17

标签: javascript jquery jquery-mobile

我在div上留下了滑动

  $(".iframe-content").swipeleft(function(e) {

        alert ("test 1");
    });

    <div class="iframe-content">
<div class="noswipe">no swipe</div>
<div class="noswipe">no swipe</div>
<div class="noswipe">no swipe</div>
<div class="noswipe">no swipe</div>
    <div id="another-swipe">swipe here</div>
<div class="noswipe">no swipe</div>
<div class="noswipe">no swipe</div><div class="noswipe">no swipe</div>
    </div>

现在我的问题恰恰是:

iframe-content 上滑动工作正常,但我在another-swipe上再次滑动

$(".another-swipe").swipeleft(function(e) {


        alert("test2")

    });

但它提供的上一个警告不是alert("test2"); ....

1 个答案:

答案 0 :(得分:1)

  1. 使用class而不是ID与另一次刷卡。

  2. 你可以使用e.stopPropagation();停止上呼叫

  3. 请点击此处(点击而不是滑动): http://jsfiddle.net/26w2q/

    HTML

    <div class="iframe-content">
        <div class="noswipe">no swipe</div>
        <div class="noswipe">no swipe</div>
        <div class="noswipe">no swipe</div>
        <div class="noswipe">no swipe</div>
        <div class="another-swipe">swipe here</div> <<< USE class instead of id
        <div class="noswipe">no swipe</div>
        <div class="noswipe">no swipe</div>
        <div class="noswipe">no swipe</div>
    </div>
    

    JQUERY

    $(".another-swipe").swipeleft(function(e) {
    e.stopPropagation();
    alert("test2")
    });
    $(".iframe-content").swipeleft(function(e) {
        alert ("test 1");
    });