锚标记中的 onclick 事件在 IE 中不起作用
以下在 Firefox 和 Chrome 中工作正常,但 IE 8 在单击锚链接时不会调用 Submit() 方法。
<a href="javascript:void(0);" onclick="submit();">Sign In</a>
在同一页面上定义了submit方法如下:
<head>
<script type="text/javascript">
function submit()
{
// other code
document.forms[0].submit();
}
</script>
</head>
The following works fine in Firefox and Chrome, but IE 8 will not call the submit() method when the anchor link is clicked.
<a href="javascript:void(0);" onclick="submit();">Sign In</a>
The submit method is defined on the same page as follows:
<head>
<script type="text/javascript">
function submit()
{
// other code
document.forms[0].submit();
}
</script>
</head>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您能提供更多背景信息吗?比如
submit
函数是在哪里以及如何定义的?有了上面的内容,它就应该可以工作了——除了:您可能还想在其中返回 false; 来取消默认操作。例如:
默认操作可能在
提交
之后立即发生并干扰它。编辑:为了好玩,请尝试为您的
submit
函数使用不同的名称。 IE 存在命名空间问题。例如,如果您有任何id
或name
属性设置为“submit”的内容,这可能是一个问题...Can you provide a bit more context? Such as where and how the
submit
function is defined? With just the above, it should work -- except:You probably also want to
return false;
in there though, to cancel the default action. E.g.:It may be that the default action is happening immediately after the
submit
and interfering with it.Edit: Just for fits and giggles, try using a different name for your
submit
function. IE has namespacing issues. If you have anything with theid
orname
attribute set to "submit", for instance, that could be an issue...对于最近遇到此问题的其他人来说,对我来说,这是由于 IE 11 在网站上使用兼容模式造成的。它看到我在同一个域上,假设该站点是一个 Intranet 站点,并自动切换到兼容模式,这破坏了一些 Javascript(并导致了一些其他意外的显示问题)。
您可以通过单击设置齿轮并选择“兼容性视图设置”来关闭此“功能”。有一个复选框被设置为“在兼容性视图中显示 Intranet 站点”。
For others who have come across this problem more recently, for me it was due to IE 11 using compatibility mode on the site. It saw I was on the same domain, assumed the site was an intranet site and automatically switched to compatibility mode which broke some of the Javascript (and caused some other unexpected display issues).
You can turn off this 'feature' by clicking on the settings cog and choosing "Compatibility View Settings". There is a tick box that was set called "Display intranet sites in Compatibility View".
尝试使用
或
Try using
or
如果您需要向 javascript 函数输入值,请确保使用单引号而不是双引号。
例如:
If you need to input the value to the javascript function, make sure that uses the single quotation instead of the double quotation.
For example: