下面是我的代码,我只是想提醒“hi”和“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-modals”关键字
当我尝试用 console.log 替换警报后,它工作正常。
您的代码工作正常,请将警报替换为 console.log()
关于javascript - jquery 函数不调用按钮单击,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31593910/