简体   繁体   English

在Mousepress期间IE9 Mousemove事件未触发

[英]IE9 Mousemove event not firing during Mousepress

When I left-click and drag the mouse, IE9 doesn't recognize the mousemove event. 当我左键单击并拖动鼠标时,IE9无法识别mousemove事件。 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. 观察Chrome,FF,Safari,Opera等中“记录器”div中的数据读数。然后在IE9中查看。 How do I get IE9 to behave like the others? 我如何让IE9像其他人一样行事?

Many thanks! 非常感谢!

I tested your code on my machine w/ Compat mode turned on, and got the issue you describe. 我在打开Compat模式的机器上测试了你的代码,并得到你描述的问题。 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: 将以下元标记添加到页面以告知IE使用最新的渲染器版本进行渲染:

<meta http-equiv="X-UA-Compatible" content="IE=edge" />

This tag will also disable the user from turning Compat Mode on for any page this is added to. 此标记还将禁止用户为添加到的任何页面打开Compat Mode。 Thus preventing them from inadvertently causing it to break. 从而防止它们无意中导致它破裂。

I added the DOCTYPE tag to the top of my HTML code and that resolved the problem: 我在我的HTML代码顶部添加了DOCTYPE标记,解决了这个问题:

<!DOCTYPE html>
<html>
<head>
<title>IE9 Failure</title>
...

Thanks to everyone who contributed. 感谢所有贡献的人。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM