두 번째 스크립트가 실행되는 이유는 무엇이며 어떻게 토글 컨트롤처럼 작동하게 할 수 있습니까?예기치 않은 스크립트 실행 순서
<script>
var el = 2;
$(document).ready(function(){
$(".rightDiv").click(function(){
if (el == 2) {
$(this).animate({left:'150px'});
el = 1;
}
});
});
</script>
<script>
$(document).ready(function(){
$(".rightDiv").click(function(){
if (el==1) {
$(this).animate({left:'50px'});
el = 2;
}
});
});
</script>
2 개의'click' 콜백을 첨부했기 때문에 두 명령문을 모두 실행합니다. 새 이벤트 핸들러를 연결하기 전에 현재 이벤트 핸들러를 제거하는 방법은 http://stackoverflow.com/questions/209029/best-way-to-remove-an-event-handler-in-jquery를 확인하십시오. – h2ooooooo