IE9 Mousemove 事件在 Mousepress 期间未触发
当我左键单击并拖动鼠标时,IE9 无法识别 mousemove 事件。我需要知道鼠标在按下状态下移动时的位置。
其他浏览器运行良好。
这是我的代码的本质:
<html>
<head>
<title>IE9 Failure</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
</head>
<body>
<div id="imgDiv"><img src="http://upload.wikimedia.org/wikipedia/en/1/1e/C.s.lewis3.JPG" alt="C.S. Lewis" /></div>
<div id="logger"></div>
<script>
$('#imgDiv').mousemove(displayMouseXYPos);
$('img').mousedown(function(event)
{
event.preventDefault();
});
var i = 0;
function displayMouseXYPos(e)
{
if (!e) var e = window.event;
var x = e.clientX + document.body.scrollLeft;
var y = e.clientY + document.body.scrollTop;
i++;
$('#logger').html(i + ') ' + x + ',' + y);
}
</script>
</body>
</html>
只需在图像上单击并拖动鼠标即可。观察Chrome、FF、Safari、Opera等中“logger”div中的数据读出,然后在IE9中查看。如何让 IE9 表现得像其他浏览器一样?
非常感谢!
When I left-click and drag the mouse, IE9 doesn't recognize the mousemove event. I need to know where the mouse is located while it is being moved during it's depressed state.
Other browsers are working great.
Here is the essence of my code:
<html>
<head>
<title>IE9 Failure</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
</head>
<body>
<div id="imgDiv"><img src="http://upload.wikimedia.org/wikipedia/en/1/1e/C.s.lewis3.JPG" alt="C.S. Lewis" /></div>
<div id="logger"></div>
<script>
$('#imgDiv').mousemove(displayMouseXYPos);
$('img').mousedown(function(event)
{
event.preventDefault();
});
var i = 0;
function displayMouseXYPos(e)
{
if (!e) var e = window.event;
var x = e.clientX + document.body.scrollLeft;
var y = e.clientY + document.body.scrollTop;
i++;
$('#logger').html(i + ') ' + x + ',' + y);
}
</script>
</body>
</html>
Just click and drag your mouse over the image. Observe the data readout in the 'logger' div in Chrome, FF, Safari, Opera, etc. Then check it out in IE9. How do I get IE9 to behave like the others?
Many thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我在打开兼容模式的机器上测试了您的代码,并得到了您所描述的问题。您的浏览器可能已打开兼容模式。
将以下元标记添加到您的页面,以告诉 IE 使用最新的渲染器版本进行渲染:
此标记还将禁止用户为添加到的任何页面打开兼容模式。从而防止他们无意中导致其破裂。
I tested your code on my machine w/ Compat mode turned on, and got the issue you describe. Your browser likely has Compatibility Mode turned on.
Add the following meta tag to your page to tell IE to render using the latest renderer version:
This tag will also disable the user from turning Compat Mode on for any page this is added to. Thus preventing them from inadvertently causing it to break.
我将 DOCTYPE 标记添加到 HTML 代码的顶部,这解决了问题:
感谢所有做出贡献的人。
I added the DOCTYPE tag to the top of my HTML code and that resolved the problem:
Thanks to everyone who contributed.