开发者

Disabled Textbox: Unexpected Values for window.event.clientX & clientY

开发者 https://www.devze.com 2022-12-17 11:33 出处:网络
I have some mouse-tracking code that isn\'t working as expected in IE that basically boils down to the HTML below. I\'ve tried this in both IE7 and IE8.

I have some mouse-tracking code that isn't working as expected in IE that basically boils down to the HTML below. I've tried this in both IE7 and IE8.

The part that's unexpected is when you mouse over the text in the disabled textbox, the values for window.event.clientX and clientY seem to be relative to that text instead of the whole window.

Can anyone explain why in this scenario, the values should be relative to the text instead of the whole window?

I guess I can likely find a workaround, but it just really surprised me.

<html>
<body>
    window.event.clientX: <br />
    <input type="text" id="foo">
    <input type="text" value="mouse over me" disabled />
</body>

<script>
    function trackMouse() {
        d开发者_如何学Goocument.getElementById('foo').value = window.event.clientX;
    }
    document.onmousemove = trackMouse;
</script>

</html>


A simple but unsatisfactory explanation is that it is a bug.

Jason Brunette supplies a similar example www.excel.net where he describes it thus:

..."bug within a bug". Mouse events shouldn't fire on disabled elements...

A similar error can be seen when using offsetX. Jan Wolter had this to say regarding the latter in Aug, 2010, at unixpapa.com

Theoretically, the event.offsetX and event.offsetY values are supposed to contain this, but forget it. There are so many bugs and incompatibilities in these values that they are essentially completely useless.

He went on to suggest the use of a combination of offsetLeft and possibly multiple offsetParents to get the same effect.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号