【发布时间】:2010-10-09 17:50:27
【问题描述】:
让我们从下面的例子开始:
在同一目录下创建三个页面: 测试.html index.html
你的 test.html:
<html>
<head>
<script>
function test()
{
alert('Going to google.com?');
window.location="http://google.com";
}
</script>
</head>
<body>
<a href='' onclick="test();">google.com</a><br/>
<input type="button" value="google" onclick="test();" />
<a href='' onmouseover="test();">google.com</a><br/>
</body>
</html>
现在在 IE 以及 firefox 或 crome 上检查 test.html 页面。
你会注意到以下几点:
- 按钮完美运行。
- 第一个超链接在 IE 和其他浏览器中的工作方式不同。在 IE 中,它让我们回到 index.html 页面,而在 Firefox 中,它停留在同一页面上。
- 对于第一个超链接,window.location 失败。
- 您不能点击第二个超链接,因为鼠标悬停事件将首先触发,而且效果很好!
为什么?
我的主要兴趣在于第三点,因为它甚至给了我们警报,window.location 失败了。
【问题讨论】:
标签: javascript html internet-explorer firefox anchor