Chrome Javascript 双警报循环?
下面这个简单的代码输出两个警报,而不是一个 Google Chrome 浏览器。 你能告诉我为什么只在 Chrome 中吗?
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Can you tell?</title>
<script language="javascript" type="text/javascript">
function hitme() {
alert('yep!');
}
</script>
</head>
<body>
<a href="#" onmouseover="hitme();">LINK</a>
</body>
</html>
chrome 是否将锚点视为文本+它的行?
Chrome 中的这个双框是什么造成的?
Thi simple code below outputs two alerts instead of one Google Chrome browser. Can you tell why only in Chrome?
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Can you tell?</title>
<script language="javascript" type="text/javascript">
function hitme() {
alert('yep!');
}
</script>
</head>
<body>
<a href="#" onmouseover="hitme();">LINK</a>
</body>
</html>
Is chrome seeing the anchor as text + it's row?
What's making this double box in Chrome?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
对鼠标悬停等事件发出警报是出了名的糟糕(阅读:不可预测)。 鼠标悬停事件处理对于状态更改非常有用,但对于诸如警报之类的某种交互则不太有效。
可能发生的情况是鼠标悬停被触发多次(注意鼠标悬停与鼠标输入不同 - 注意:没有得到很好的支持)请参阅 http://www.quirksmode.org/js/events_mouse.html 了解有关鼠标事件的更多详细信息。
重要的是要注意不同的浏览器处理事件的方式不同。 例如,在大多数浏览器中,mousemove 仅在鼠标移动时才会触发,但在 Firefox 中(如果我没记错的话)它几乎会不断触发。 鼠标悬停也是如此,如果你真的很幸运,你会得到一堆警报窗口,在鼠标悬停在某个元素上的那半秒内关闭。
alerting on events like mouseover is notoriously bad (read: unpredictable). mouseover event handling is great for a state change but less so for some kind of interaction like an alert.
What is likely happening is the mouseover is being fired multiple times (note mouseover is not the same as mouseenter -- note: not well supported) see http://www.quirksmode.org/js/events_mouse.html for more details on mouse events.
It's important to be aware that different browsers handle events differently. mousemove, for example, is only fired when the mouse moves in most browsers, but in firefox (if I recall correctly) it is almost constantly firing. Ditto for mouseover, and if you're really lucky, you get a stack of alert windows to close for that half second your mouse was over an element.
我猜这与窗口焦点有关; 如果您将鼠标移动到链接上的速度足够快,您只会看到一个警告框。 在 Mac 版 Safari 中不会发生这种情况。
I'm guessing it's something to do with window focus; if you move the mouse over the link quick enough you get only one alert box. Doesn't happen in Safari for Mac fwiw.
我的第一个建议是尝试 Safari,这将明确问题是否特定于 chrome(例如 chrome bug)或一般的 webkit(因此在所有基于 webkit 的浏览器中)。 可以想象,要么是:D
(对于那些有这个答案的人来说,我的假设是场景是
鼠标悬停元素 -> Alert() 中,警报被指定为模态,因此不会再将鼠标悬停在该元素上,并且我假设解除警报发生在包含 div 的区域之外。 在这种情况下,无论浏览器之间的事件模型有何差异,出现两个对话框都是不正确的。 此外,Chrome 足够“有趣”,以至于它很可能成功地搞乱了 webkit 之上的事件处理,因此我建议这可能是一个 chrome bug)
My first suggestion would be to try Safari this will make it clear whether the issue is specific to chrome (Eg. a chrome bug) or webkit in general (so across all webkit based browsers). It's conceivably either :D
(note for the people who have -'d this answer my assumption was that the scenario was
mouseover element -> alert(), the alert is specified as being modal, so there will be no further mouse overs to the element, and i assumed dismissing the alert occurred outside of the area containing the div. In this scenario it is incorrect for two dialogs to come up, regardless of event model differences between browsers. Further Chrome is sufficiently "interesting" to make it highly possible that it has managed to mess up event handling above webkit proper, hence my suggestion it may be a chrome bug)