2014-12-02 80 views
-1

我在document.ready中收到異常,因爲$是未定義的,爲什麼? 如果我刪除了document.ready函數,其他jquery代碼工作正常。以下是我的代碼Document.ready不起作用,但其他jQuery代碼正在工作?

<script type="text/javascript"> 
     $(document).ready(function() { alert('Hi'); }); 
     function LoginTypeChanged() { 
      if ($('#loginType option:selected').val() === "1") { 
       $("#txtUserName").prop('disabled', false); 
       $("#txtPassword").prop('disabled', false); 
       $("#txtDomain").prop('disabled', false); 
      } 
      else if ($('#loginType option:selected').val() === "0") { 
       $("#txtUserName").val(""); 
       $("#txtPassword").val(""); 
       $("#txtDomain").val(""); 
       $("#txtUserName").prop('disabled', true); 
       $("#txtPassword").prop('disabled', true); 
       $("#txtDomain").prop('disabled', true); 

      } 
     } 
</script> 
+8

如果您收到'$是undefined'這意味着你沒有在頁面包括jQuery的正確。 – 2014-12-02 14:22:22

+0

你可以製作一個[JSFiddle](http://jsfiddle.net/)重新創建你的問題。 – Danny 2014-12-02 14:23:35

+0

你必須把''之前的任何代碼,實際上使用jQuery。 – 2014-12-02 14:24:21

回答

0

有2個可能的問題:

  1. 你缺少jQuery的參考的jQuery腳本前加入的

  2. 腳本代碼。

+1

感謝ianaya,我在head標籤中添加了腳本並且它的工作原理。以前它在html的底部。 – avinash 2014-12-02 14:32:22

+0

@avinash酷,如果它適合你,請接受答案。 – ianaya89 2014-12-02 14:36:00

+1

接受了你的回答。謝謝 – avinash 2014-12-03 06:48:24

0

你需要添加像這樣

<script src="//code.jquery.com/jquery-1.10.2.js"></script> 
相關問題