Jquery 无法正常单击按钮

问题描述 投票:0回答:1

非常简单的代码,由于某种原因,我尝试的任何方法都不起作用!我显然已经导入了 Jquery、jqueryUI、ajax、所有我需要导入的东西(不止一次!)。但由于某种原因,不想使用 Jquery 单击此按钮!我让它与 onClick 一起工作,但我想为此使用 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>
javascript jquery button click
1个回答
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();
          });

   });
© www.soinside.com 2019 - 2024. All rights reserved.