简体   繁体   English

单击按钮后不会显示隐藏的表单

[英]Hidden form doesn't show up on button click

On button click, I am trying to display a form which is hidden. 单击按钮时,我试图显示一个隐藏的表单。 However, I do not understand why it is not showing up. 但是,我不明白为什么它没有显示出来。

I've tried the following code 我尝试了以下代码

 $(document).ready(function() { $("#button_id").click(function() { $("#form_id").show(); //Form shows on button click }); }); 
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <!DOCTYPE html> <html> <head> <title>Myapp</title> <script type="text/javascript"> </script> </head> <body> <input type="button" name="button" value="button" id="button_id" onclick="ready();"> <form id="form_id" action="" method="POST" style="display:none;"> <input type="id" name="login[id]" placeholder="id"><br> <input type="username" name="login[username]" placeholder="username"><br> <input type="password" name="login[password]" placeholder="password"><br> <input type="submit" name="submit" class="submit"> </form><br> </body> </html> 

Remove onclick="ready();" 删除onclick="ready();" from your button's HTML as that attribute is: 在按钮的HTML中,该属性为:

  1. Not needed because you've already set up the click handler with your JQuery. 不需要,因为您已经使用JQuery设置了click处理程序。
  2. References a non-existent ready() function and causes an error. 引用不存在的ready()函数并导致错误。

 $(document).ready(function() { $("#button_id").click(function() { $("#form_id").show(); //Form shows on button click }); }); 
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <input type="button" name="button" value="button" id="button_id"> <form id="form_id" action="" method="POST" style="display:none;"> <input type="id" name="login[id]" placeholder="id"><br> <input type="username" name="login[username]" placeholder="username"><br> <input type="password" name="login[password]" placeholder="password"><br> <input type="submit" name="submit" class="submit"> </form> 

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

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