onsubmit =“返回false”对Internet Explorer 7/8没有影响(表单仍提交) [英] onsubmit="return false" has no effect on Internet Explorer 7/8 (form is still submitted)

查看:202
本文介绍了onsubmit =“返回false”对Internet Explorer 7/8没有影响(表单仍提交)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个表单,将通过标记的onsubmit触发的JavaScript代码提交。在所有浏览器上都能正常工作 - 但不能在IE7 / IE8上使用。

I have a form that will be submitted by javascript code triggered in "onsubmit" of the tag. Works fine on all browsers - but not on IE7/IE8.

我能做什么?

What can I do?

<form action="/dosomething.htm" method="GET" onsubmit="submitmyform();return false">
  [...]
  <input type="submit" value="Go">
</form>


推荐答案

我要挑选这个。如果你想处理表单提交,这是提交的目的。如果用户点击进入您的某个字段,则您的onclick处理程序将完全避免。

I'm going to nitpick this. If you want to handle form submissions, that is what submit is for. If the user hits enter in one of your fields, your onclick handler will be totally avoided. Here is a basic example of doing this in a non-obtrusive way.

<form name="myform">
  <input type="submit" />
</form>
<script>
  document.myform.onsubmit = function(){
    alert('handled');
    return false;
  }
</script>

使用jQuery,这种方式可以变得更简单...

This can be made a lot simpler with jQuery, same form...

$("form[name=myform]").bind('submit',function(){
   alert('handled');
   return false;
});

这篇关于onsubmit =“返回false”对Internet Explorer 7/8没有影响(表单仍提交)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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