.show()方法不能像在jquery中那样工作

我有一个div在css中显示none(display:none;)但是当我使用jquery .show()方法时,它只在页面上闪烁一秒钟。 这是我的HTML代码



Confirm Password:


Account Type:
Advertiser Publisher

Company Name:


Email address:


Country:




这是我的css代码

  .hide{ display:none; } 

以下是jquery代码

  $(document).ready(function(){ $(".hide").hide(); $("#create").click(function(){ $(".hide").show(); }); }); 

创建按钮是type="submit" 。 您需要在窗体的“submit”事件中调用event.preventDefault()(使该事件回调采用名为event的参数),或者将id =“create”的输入更改为type=button

我会将其更改为type="button" ,因为我怀疑你想要一个“Enter”按键来按下Create。 如果在表单中按下回车键,则提交按钮是默认设置。

创建表单“消失”,因为创建按钮的提交(重新)加载了login.php页面。

如果’#create’来自其他来源,请尝试此操作: 事件委派

 $(document).ready(function(){ $(".hide").hide(); $(document).on('click','#create',function(){ $(".hide").show(); }); }); 

为什么不完全删除#create类并像这样定位元素#create

 $(document).ready(function(){ $("#signup").hide(); $("#create").click(function(){ $("#signup").show(); }); });