pageX pageY在IE8中不工作,如果我添加<!DOCTYPE html> [英] pageX pageY not working in IE8 if i add <!DOCTYPE html>

查看:220
本文介绍了pageX pageY在IE8中不工作,如果我添加<!DOCTYPE html>的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下脚本,当我移动鼠标时,它给了我光标位置。
这个脚本在chrome,FF甚至IE 8中都没问题(没有!doctype html

!DOCTYPE html 到html页面。
它给了我对象不支持这个属性错误。并且下面给出的行导致了问题


$ b document.captureEvents(Event.MOUSEMOVE);



如何解决IE 8中包含的!DOCTYPE html 问题。

  window.onload = init; 
函数init(){
if(window.Event){
document.captureEvents(Event.MOUSEMOVE);
}
document.onmousemove = getCursorXY;
}

函数getCursorXY(e){
document.getElementById('cursorX')。value =(window.Event)? e.pageX:
event.clientX +(document.documentElement.scrollLeft?
document.documentElement.scrollLeft:document.body.scrollLeft);
document.getElementById('cursorY')。value =(window.Event)? e.pageY:event.clientY
+(document.documentElement.scrollTop?document.documentElement.scrollTop:
document.body.scrollTop);


解决方案

错误,因为<!DOCTYPE html> 是HTML5的声明,IE 8将无法处理HTML5。



你有没有考虑切换到jQuery?它将具备实现相同功能所需的所有功能。


Hey guys i have the following script which gives me cursor position when i move the mouse . this script works fine in chrome,FF and even in IE 8(without !doctype html)

if add !DOCTYPE html to the html page. it gives me object doesnt support this property error. and the below given line is causing the problem

document.captureEvents(Event.MOUSEMOVE);

How can i fix this problem with !DOCTYPE html included in IE 8.

window.onload = init;
    function init() {
   if (window.Event) {
    document.captureEvents(Event.MOUSEMOVE);
   }
  document.onmousemove = getCursorXY;
    }

  function getCursorXY(e) {
      document.getElementById('cursorX').value = (window.Event) ? e.pageX :   
         event.clientX + (document.documentElement.scrollLeft ?    
       document.documentElement.scrollLeft : document.body.scrollLeft);
     document.getElementById('cursorY').value = (window.Event) ? e.pageY : event.clientY  
   + (document.documentElement.scrollTop ? document.documentElement.scrollTop :    
    document.body.scrollTop);
    }

解决方案

I assume you are receiving the error because <!DOCTYPE html> is the declaration for HTML5 and IE 8 won't be able to process HTML5.

Have you considered to switch to jQuery? It will have all the functions needed to achieve the same.

这篇关于pageX pageY在IE8中不工作,如果我添加&lt;!DOCTYPE html&gt;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆