Jquery无法正常工作按钮点击

问题描述:

非常简单的代码,由于某种原因我没有尝试将工作!我显然已经导入了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) –

裹你$(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