锚标记中的onclick事件在IE中不起作用 [英] onclick event in anchor tag not working in IE

查看:95
本文介绍了锚标记中的onclick事件在IE中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下内容在Firefox和Chrome中正常运行,但是单击锚点链接时IE 8不会调用commit()方法.

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>

submit方法在同一页面上定义如下:

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>

推荐答案

能否提供更多上下文?例如在何处以及如何定义 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:

您可能还想在其中 return false; 来取消默认操作.例如:

You probably also want to return false; in there though, to cancel the default action. E.g.:

<a href="javascript:void(0);" onclick="submit();return false;">Sign In</a>

默认操作可能是在 submit 提交之后立即进行的,并且会对其产生干扰.

It may be that the default action is happening immediately after the submit and interfering with it.

编辑:为了适应和咯咯地笑,请尝试为您的 submit 函数使用其他名称.IE浏览器存在命名空间问题.例如,如果您将 id name 属性设置为提交",则可能是一个问题...

Edit: Just for fits and giggles, try using a different name for your submit function. IE has namespacing issues. If you have anything with the id or name attribute set to "submit", for instance, that could be an issue...

这篇关于锚标记中的onclick事件在IE中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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