[英]Javascript/jquery - onclick of a button
I'm stuck with a strange problem where a javascript function isn't getting invoked when I click on submit button(LOG IN)
from inside a form. 我遇到了一个奇怪的问题,当我从表单内部单击submit button(LOG IN)
时,没有调用javascript函数。
<html>
<head>
<title></title>
<script>
$('#loginBtn').click(function () {
$(this).html('<img src="http://www.bba-reman.com/images/fbloader.gif" />');
});
</script>
</head>
</html>
Is there anything different I should do here? 我在这里应该做些什么吗? I'm unable to figure this out. 我无法弄清楚这一点。 Please could I ask for help? 我可以请求帮助吗?
Remove the extra )
at the end of function hideBtn()
. 删除多余的)
在结束function hideBtn()
It should look like this 它看起来应该是这样的
function hideBtn(){
alert('hello');
};
<html> <head> <title></title> <link rel="stylesheet" type="text/css" href="app/js/bootstrap/css/bootstrap.min.css"> <link rel="stylesheet" type="text/css" href="app/js/bootstrap/css/bootstrap-theme.min.css"> <link rel="stylesheet" type="text/css" href="app/css/bootsnipLogin.css"> <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <script type="text/javascript" src="app/js/bootstrap/js/bootstrap.min.js"></script> <script type="text/javascript" src="app/js/login.js"></script> <link rel="shortcut icon" href="app/image/favicon.ico" /> </head> <body > <div class="container"> <div class="card card-container"> <br/> <center><img src="app/image/wd-logo.gif"></center> <br/><br/> <img id="profile-img" class="profile-img-card" src="app/image/avatar_2x.png" /> <br/> <p id="profile-name" class="profile-name-card"></p> <form class="form-signin" action="" method="post"> <input id="username" name="username" placeholder="User Name" class="form-control" required autofocus> <br/><br/><br/> <input type="password" id="password" name="password" placeholder="Password" class="form-control" required > <br/><br/><br/> <div align="center"> <span id = "errorspan"><?php echo $error; ?></span> </div> <br/><br/><br/> <button class="btn btn-lg btn-primary btn-block btn-signin" type="submit" name="submit" id="loginBtn">SIGN IN</button> </form><!-- /form --> </div><!-- /card-container --> </div><!-- /container --> <script> $('#loginBtn').click(function(){ // alert('as'); $(this).html('<img src="http://www.bba-reman.com/images/fbloader.gif" />'); }); </script> </body> </html>
There's an extra ');' 有额外的');' in your script. 在你的脚本中。 Remove it and it will work. 删除它,它会工作。
function hideBtn(){
//$(this).html('<img src="http://www.bba-reman.com/images/fbloader.gif" />');
alert('hello');
}
Remove the extra ) then your code will work properly like below 删除额外的)然后您的代码将正常工作,如下所示
function hideBtn()
{
alert('Hii');
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.