jQuery提交功能无法正常工作 [英] jQuery submit function not working properly

查看:95
本文介绍了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();
});

这篇关于jQuery提交功能无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆