jQuery提交功能无法正常工作

jam*_*ame 2 jquery submit

我对jQuery提交功能有一些疑问.

这是工作环境

jQuery:1.7.2,chrome(18.0.1025.168 m).

有两个问题.

第一名:

我的代码是这样的

HTML

<form id="test" action="..." method="post">
     <input type="text" />
     <input type="submit">
</form>
Run Code Online (Sandbox Code Playgroud)

jQuery的

$('#test').submit(function(){
      return false;
})
Run Code Online (Sandbox Code Playgroud)

问题是它在firefox和opera中工作得很好但是chrome.

2ST:

html:如上所述.

jQuery的:

$('#test').submit(function(){
      if(...)
         alert(something..);
      return false;
})
Run Code Online (Sandbox Code Playgroud)

它不适用于firefox,opera和chrome.它总是触发form.submit为什么.

我很困惑.谁能想出来谢谢!

Hac*_*ese 11

不要用return false;.试试这个:

$('#test').submit(function(event){
      event.preventDefault();
});
Run Code Online (Sandbox Code Playgroud)

  • 我确实得到了同样的模糊downvote与相同的"co-answerer(s)"[这里](http://stackoverflow.com/questions/10572004/drop-down-list-display-div-when-clicking-an-选项/).似乎有点奇怪. (3认同)
  • 所以我想我不会因为说iambriansreed与其他人不能很好地合作,尽管事实上我在他做了差不多一分钟之前回答. (3认同)