2013-05-30 3 views
0

HTML 페이지에서 클릭 한 후 단추를 숨기려면 기본 Jquery 스크립트를 작성하고 있습니다. 그러나 버튼을 클릭하면 아무 것도 수행하지 않습니다. 코드는 다음과 같습니다. JQuery가 최신 버전으로 업데이트되었습니다.JQuery가 제대로 초기화되지 않습니다.

<!DOCTYPE html> 
<html> 
<head> 
<title>Test Page</title> 
<script type = "text/javascript"> 

$(document).ready(function(){ 
    $('#button').click(function(){ 
     $('#button').toggle(); 
    }); 
}); 

</script> 
<script type = "text/javascript" src="jquery-2.0.1.js"></script> 
<link rel="stylesheet" type="text/css" href="style.css"> 
</head> 

<body> 

<div id = "button">Find Printer</div> 

</body> 
+0

당신이 JQuery와'왜) ('.toggle를 사용하는 나 => http://jsfiddle.net/39E9p/ – Gabe

+0

작품을로드하는 긍정적인가? 그것을 숨기면 다시 클릭 할 수 없습니다! 그냥 .hide()를 사용하십시오. – PlantTheIdea

+1

에 대한 ... 확인 피들러, 디버거 ... –

답변

7

$(document).ready()을 사용하기 전에 먼저 jquery를로드해야합니다. 자바 스크립트 태그 위의 jQuery 스크립트 태그를 이동하십시오.

<!DOCTYPE html> 
<html> 
<head> 
<title>Test Page</title> 
<script type = "text/javascript" src="jquery-2.0.1.js"></script> 
<script type = "text/javascript"> 

$(document).ready(function(){ 
    $('#button').click(function(){ 
     $('#button').toggle(); 
    }); 
}); 

</script> 
<link rel="stylesheet" type="text/css" href="style.css"> 
</head> 

<body> 

<div id = "button">Find Printer</div> 

</body> 
+0

도움 주셔서 감사합니다 :) – Jpm61704

1

jQuery를로드하기 전에 스크립트가로드되었습니다. 코드 블록 전에 jQuery 링크를 이동하면 정상적으로 작동합니다.

0

먼저 jQuery를 스크립트를로드 시도하고 $(document).ready()를 호출합니다.

관련 문제