jQuery提交功能无法正常工作

问题描述:

我对jQuery提交功能有疑问.

I have some questions with jQuery submit function.

这是工作环境

jQuery:1.7.2,chrome(18.0.1025.168 m).

jQuery: 1.7.2, chrome (18.0.1025.168 m).

有两个问题.

第一:

我的代码是这样的

html

<form id="test" action="..." method="post">
     <input type="text" />
     <input type="submit">
</form>

jQuery

$('#test').submit(function(){
      return false;
})

问题在于它在Firefox和Opera中可以正常运行,但在chrome中可以正常运行.

the problem is it works fine in firefox and opera but chrome.

第二个:

html:如上所述.

html: as above.

jQuery:

$('#test').submit(function(){
      if(...)
         alert(something..);
      return false;
})

它不适用于Firefox,Opera和Chrome.它总是触发form.submit原因.

it dosen't work in firefox,opera and chrome. it always trigger form.submit why.

我很困惑.谁能弄清楚谢谢!

I am very confused it. who can figure it out thanks!

请勿使用return false;.尝试以下方法:

Don't use return false;. Try this instead:

$('#test').submit(function(event){
      event.preventDefault();
});