简体   繁体   English

jQuery函数不调用按钮单击

[英]jquery function not calling on button click

Below is my code, i just want to alert the "hi" and "hello" so that i can put my actual codes there. 下面是我的代码,我只想提醒“ 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>

button click event is not working, i am using the same jquery library in some other places which is working fine. 按钮单击事件不起作用,我在其他一些地方使用相同的jquery库,效果很好。 I have to call ajax in this page i need to call the button click without submitting the page, as i have few more buttons to add. 我必须在此页面中调用ajax,我需要在不提交页面的情况下单击按钮单击,因为我还有几个要添加的按钮。 Any piece of code is appreciated and thanks in advance. 任何代码段均应表示感谢,并在此先感谢。

when i tried your code i got this error 当我尝试您的代码时,出现此错误

Ignored call to 'alert()'. 忽略了对“ alert()”的调用。 The document is sandboxed, and the 'allow-modals' keyword is not set 该文档已被沙箱化,并且未设置'allow-modals'关键字

and when i tried after replacing alert's with console.log then it is working fine. 当我用console.log替换警报后尝试运行时,它工作正常。

Your code is working fine, replace alert's with console.log() 您的代码运行正常,用console.log()替换警报

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM