[英]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中,该属性为:
click
handler with your JQuery. click
处理程序。 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.