onsubmit=“return false” has no effect on Internet

2019-01-19 16:02发布

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>

14条回答
Fickle 薄情
2楼-- · 2019-01-19 16:28

If you want IE to be standards compliant, you'll have to tell it which standard it's supposed to comply with in a declaration.

Without one it's going to be endless frustration to get it to do what you want. With one, most of the frustration goes away because it starts working as every other browser.

查看更多
手持菜刀,她持情操
3楼-- · 2019-01-19 16:29

It works - check W3Scools example (taken from ) http://www.w3schools.com/js/js_form_validation.asp

<html>
<head>
<script type="text/javascript">
function validate_required(field,alerttxt)
{
with (field)
  {
  if (value==null||value=="")
    {
    alert(alerttxt);return false;
    }
  else
    {
    return true;
    }
  }
}

function validate_form(thisform)
{
with (thisform)
  {
  if (validate_required(email,"Email must be filled out!")==false)
  {email.focus();return false;}
  }
}
</script>
</head>

<body>
<form action="submit.htm" onsubmit="return validate_form(this)" method="post">
Email: <input type="text" name="email" size="30">
<input type="submit" value="Submit">
</form>
</body>

</html>
查看更多
登录 后发表回答