onsubmit =&“返回假".对Internet Explorer 7/8无效(仍在提交表单) [英] onsubmit="return false" has no effect on Internet Explorer 7/8 (form is still submitted)

查看:89
本文介绍了onsubmit =&“返回假".对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.

我该怎么办?

<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 =&amp;“返回假".对Internet Explorer 7/8无效(仍在提交表单)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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