Jquery无法正常按下按钮

时间:2015-10-19 16:11:24

标签: javascript jquery button click

非常简单的代码,由于某些原因,我尝试的任何东西都无法运行!我显然已经导入了Jquery,jqueryUI,ajax,我需要导入的所有东西(不止一次!)。但由于某种原因,这个按钮不希望使用Jquery点击!我让它与onClick一起工作,但我想为此使用jquery。 SOS!

<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>

1 个答案:

答案 0 :(得分:2)

使用$(document).ready(function() {})包装jquery代码,以确保在使用jQuery访问它们之前已加载所有DOM对象:

 $(document).ready(function() {

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

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

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

   });