Jquery函数不调用按钮点击

jquery function not calling on button click

本文关键字:按钮 调用 函数 Jquery      更新时间:2023-09-26

下面是我的代码,我只是想提醒"hi"answers"hello",这样我就可以把我的实际代码放在那里。

<html>
<head>
<script type="text/javascript"  src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script type="text/javascript">
if (typeof jQuery == 'undefined') {
    document.write(unescape("%3Cscript src='jquery-1.11.1.min.js' type='text/javascript'%3E%3C/script%3E"));
}
</script>
  <script src="jquery-ui.js"></script>
        <link rel="stylesheet" href="jquery-ui.css">
</head>
<script>
$(document).ready(function(){
    alert("hi");
    $('form[name="lgform"]').submit(function(evnt){
        evnt.preventDefault();
    });
    $("#btn_login").click(function(){       
        alert("hello");
    });
});
</script>
<body>
<form name="lgform">
<div>
<table id="table"  >
    <tr>
        <td width="35px"><input id="mob"  type="text" name="mob_nu"></td>
        <td width="35px"><input id="pswd"  type="password" name="pswd_vl"></td>
        <td width="100px"><input type="button" name="login_btn" id="btn_login" value="Login"></td>          
    </tr>
</table>
</div>
</form>
</body>
</html>

按钮点击事件不工作,我在其他一些地方使用相同的jquery库工作良好。我必须调用ajax在这个页面我需要调用按钮单击而不提交页面,因为我有几个更多的按钮添加。任何一块代码是赞赏和感谢提前。

当我尝试你的代码时,我得到了这个错误

忽略对'alert()'的调用。文档是沙盒的,'allow-modal '关键字没有设置

当我尝试用console.log替换alert后,它工作得很好。

你的代码工作正常,用console.log()

替换alert's