2013-08-23 3 views
0

이것은 바보처럼 들릴지 모르지만 저는 Jquery 멍청한 놈입니다. div 태그를 만들 때 크기를 조정하려고 할 때 휴대 전화에서 좌우로 쓸어 넘기면 왜 한 번만 실행됩니까? 어떤 jquery 전문가가 여기 나를 도울 수 있을까 !! 당신에게jquery 함수가 한 번만 작동하는 이유는 무엇입니까?

감사합니다 여기에 코드

에게 있습니다
<!doctype html> 
<html lang="en"> 
<head> 
    <meta charset="utf-8"> 
    <meta name="viewport" content="width=device-width, initial-scale=1"> 
    <script src="http://code.jquery.com/jquery-1.9.1.min.js"></script> 
    <script src="http://code.jquery.com/mobile/1.3.2/jquery.mobile-1.3.2.min.js"></script> 
</head> 
<body> 

    <div class="box"> 
    </div> 

    <script> 
    $(function right(){ 
     // Bind the swiperightHandler callback function to the swipe event on div.box 
     $("div.box").on("swiperight", swiperightHandler); 

     // Callback function references the event target and adds the 'swiperight' class to it 
     function swiperightHandler(event){ 
     $(event.target).addClass("swiperight"); 
     } 
    }); 

    $(function left(){ 
     // Bind the swiperightHandler callback function to the swipe event on div.box 
     $("div.box").on("swipeleft", swiperightHandler); 

     // Callback function references the event target and adds the 'swiperight' class to it 
     function swiperightHandler(event){ 
     $(event.target).addClass("swipeleft"); 
     } 
    }); 
    </script> 
</body> 
</html> 

답변

1

당신은 제거하고 클래스

function swiperightHandler(event){ 
    $(event.target).removeClass('swipeleft').addClass("swiperight"); 
} 

function swiperightHandler(event){ 
    $(event.target).removeClass('swiperight').addClass("swipeleft"); 
} 
+0

thx 얘들 아! 그것을 해결했다. 필자는 필자가 왜 문서를 파헤쳐야 하는지를 이해할 필요가 있다고 생각한다 : p –

0

그것은 아마도 이미 요소에 클래스를 추가됩니다 당신이 두 번째를 호출 할 때, addClass는 아무것도하지 않습니다 번 이상 실행중인!

+0

들으 사람을 추가 할 필요가! 그것을 해결했다. 나는 지금 왜 그 이유를 이해하기 위해 문서를 파낼 필요가 있다고 생각한다 : p –

관련 문제