2011-08-11 5 views
2

이것은 나를 미치게 만드는 초보자 질문입니다. jQuery mobile site에 따르면, 나는 jQueryjQuery mobile을 HTML의 head에 포함시켰다.jQuery 모바일 중복 이벤트

그러면 모든 이벤트에 대해 listeneres를 할당 할 때 두 번 실행됩니다. 예 : 그 슬라이드 DIV를 누릅니다 (또는 데스크톱 브라우저에서 클릭)하면

<!doctype html> 
<html> 
    <head> 
     <meta http-equiv="imagetoolbar" content="false" /> 
     <meta name="apple-mobile-web-app-capable" content="yes" /> 
     <meta name="apple-mobile-web-app-status-bar-style" content="black" /> 
     <style> 
      .slide {width:400px; height:400px; padding:40px; border:1px solid black;} 
     </style> 
     <link href="http://code.jquery.com/mobile/latest/jquery.mobile.min.css" rel="stylesheet" type="text/css" /> 
     <script src="http://code.jquery.com/jquery-1.6.2.min.js"></script> 
     <script src="http://code.jquery.com/mobile/latest/jquery.mobile.min.js"></script> 
    </head> 
    <body> 
     <div class="slide"> 
      <h1>1</h1> 
     </div> 
     <script type="text/javascript">  
      $(function() { 
         $('.slide').tap(function() { 
          alert('tapped!'); 
         }); 
        }); 
     </script> 
    </body> 
</html> 

다음, 이 경고 표시됩니다. jQuery 모바일을 포함하여 줄을 주석 처리하면 한 번만 실행됩니다.

여기에 따라야 할 행은 무엇입니까?

답변

5

스크립트를 <head> 태그로 이동하면 해당 스크립트는 한 번만 실행됩니다. 나는 이것이 jQuery Mobile의 미친 페이지 캐싱과 관련이 있다고 생각합니다.

+0

신난다. 정상적으로 작동한다. 감사합니다 :] –

+0

어떤 지점에서이 문제가 다시 발생하면 (내가 한),'die '를 통해 바운드 이벤트를 다시 제거 할 수 있습니다. 그래도 그건 나쁜 습관이라고 생각합니다. - http://api.jquery.com/die/ – Smamatti