2014-10-07 52 views
-6

在最近的帖子Load javascript after 2 clicks on website我問了一個JavaScript問題。從js到腳本

$(function(){ 
      var count = 1 
      $(document).click(function(){ 
      if(count<=2){ 
       count+=1; 
      } 
      else{ 
       alert("already clicked two times"); 
      } 
     }); 
    }) 

現在的問題,我想有這樣的JavaScript它在我裏面<head>腳本標記,但隨後這個腳本不會工作,有人可以幫助我通過他們將如何編寫腳本?謝謝!!

更新:

<head> 
    <script> 
    $(function(){ 
      var count = 1 
      $(document).click(function(){ 
      if(count<=2){ 
       count+=1; 
      } 
      else{ 
       alert("already clicked two times"); 
      } 
     }); 
    }) 
    </script> 
    </head> 
+2

告訴我們它 「將無法正常工作」 是不是非常有幫助。告訴我們您嘗試使用''一樣簡單。 – meagar 2014-10-07 06:51:02

+0

它處於一個準備好的事件處理程序中,所以沒有明顯的理由說明爲什麼把它放在''中會破壞事情。 – Quentin 2014-10-07 06:52:35

+0

嗯,它不工作。如果我把它放在一個腳本標籤和一個 – user3637351 2014-10-07 06:54:13

回答

0
Please add JQuery library file.. 

<script src="http://code.jquery.com/jquery-1.10.2.min.js"></script> 
This code related to JQuery so without JQuery library we can not run this code. 
0

你應該包括jQuery庫第一:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> 
<script> 
$(function(){ 
    var count = 1 
    $(document).click(function(){ 
    if(count<=2){ 
     count+=1; 
    } 
    else{ 
     alert("already clicked two times"); 
    } 
    }); 
}) 
</script>