2015-10-19 61 views
-1

非常簡單的代碼,由於某種原因我沒有嘗試將工作!我顯然已經導入了Jquery,jqueryUI,ajax,我需要導入的所有東西(不止一次!)。但由於某種原因,這個按鈕不想用Jquery點擊!我知道它與onClick合作,但我想爲此使用jquery。 SOS!Jquery無法正常工作按鈕點擊

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script> 
<link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/themes/smoothness/jquery-ui.css"> 
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js"></script> 
<script src="jquery-1.11.3.min.js"></script> 

<script> 

$("#heyo").click(function(){ 
alert(); 
}); 

$("input").click(function(e){ 
var id1 = e.target.id; 
alert(id1); 
}); 

$('input[type="button"]').click(function(){ 
alert(); 
}); 

function pie(){ 
//alert(); 
} 

</script> 

<body> 
loading... 
<input type="button" id="heyo" onclick="pie()" value="ff" /> 
</body> 
+2

的[可能的複製爲什麼jQuery的或DOM方法等的getElementById不找到元素?](http://stackoverflow.com/questions/14028959/why-does-jquery-or-a-dom-method-such-as-getelementbyid-not-find-the-element) –

回答

2

裹你$(document).ready(function() {}) jQuery代碼,以確保所有的DOM對象已經加載了jQuery的訪問之前:

$(document).ready(function() { 

     $("#heyo").click(function(){ 
     alert(); 
     }); 

     $("input").click(function(e){ 
      var id1 = e.target.id; 
      alert(id1); 
     }); 

     $('input[type="button"]').click(function(){ 
      alert(); 
      }); 

    }); 
+0

AHHH OMG謝謝你我忘了那個!哇,我現在覺得愚蠢:) – sgrutman978

+1

不用擔心老兄 – KAD

+0

會JQuery的.click工作按鈕動態添加從Ajax調用? – sgrutman978