简体   繁体   English

Javascript / jquery - 点击按钮

[英]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.

相关问题 使用jQuery或Javascript通过按键触发“按钮onClick” - Trigger a “button onClick” with a keypress with jQuery or Javascript 使用onClick而不使用jQuery创建AJAX JavaScript按钮 - Creating an AJAX JavaScript Button w/ onClick and no jQuery onClick按钮不起作用javascript / php / jquery mobile - onClick button not working javascript/php/jquery mobile 通过 javascript/jquery 添加一个带有 onclick 功能的按钮 - Adding a button, with onclick function, via javascript/jquery 使用JQuery / JavaScript在.append()中添加带有onclick事件的按钮 - Adding button with onclick event in .append() with JQuery/JavaScript Javascript(非jquery)按钮onclick,函数更改按钮调用函数的类 - Javascript(not jquery) button onclick, function changes class of button calling function 如何使用javascript或jquery创建动态tbody onclick按钮 - How to Create dynamic tbody onclick of button using javascript or jquery 按钮的onclick功能无法在form.javascript中工作 - Onclick function of button can not work in form.javascript jquery JQUERY附加带有onClick事件的按钮并在其中传递javascript变量 - JQUERY appending a button with onClick event and passing javascript variable in it 用于显示饼图的onclick()jQuery / JavaScript按钮不起作用 - onclick() jQuery/JavaScript Button to display piechart doesn't work
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM