<!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> 
    <title> New Document </title> 
<script language="JavaScript"> 
<!-- 
function show(event) 

_event = event ||window.event;xx2= _event.pageX||_event.clientX; 
alert(xx2); 

//--> 
</script> 
</head> <body> <div style="width:400px;height:100px;background-color:#00FFFF" onmousemove="show(event);"> </div> </body> 
</html>

解决方案 »

  1.   

    在你代码基础上改进了下 可以试试!!
    <!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> 
        <title> New Document </title> 
    </head> <body> 
    <div id="test" style="width:400px;height:100px;background-color:#00FFFF"> </div> 
    </body> 
    <script language="JavaScript"> 
    <!-- 
    /**
    //判断浏览器类型(IE)
    **/
    function isIE() {
    return navigator.appName == "Microsoft Internet Explorer";
    }
    /**
    //判断浏览器类型(Firefox)
    **/
    function isFirefox() {
    return navigator.userAgent.indexOf("Firefox") > 0;
    }
    document.getElementById("test").onmousemove = function(F) {
    var evt;
    if (isIE()) {
    evt = window.event
    } else if (isFirefox()) {
    evt = F;
    }
    xx2=evt.pageX;
    alert(xx2); 
    };
    //--> 
    </script> 
    </html>
      

  2.   

    你这个方法很好,但是我不明白为什么 show要传递一个参数过去?
    在FF下,为什么直接event.pageX就不行? 这个event非要通过JS函数传递过去?
      

  3.   

    呵呵,
    你要理解w3c 事件机制,
    <div id = 'div1' style="width:400px;height:100px;background-color:#00FFFF" onmousemove="show(event);">
    这种加事件
    是旧的DOM0事件机制,调用show()其实是这样的
    function anonymous()
    {
       show();
    }
    所以调用show ()调用被anonymous 调用
    所以
    show(event) 加个event 参数anonymous(在Firefox下)会把事件传递进去.在IE 事件不会传递的.
    所以加了个判断 _event = event ||window.event;DOM2新的事件机制跟DOM0 处理事件传递参数很大程度不同
    如果你是用DOM2时间机制,
    你可以
    document.getElementById('div1').onclick=function()
    {}
    或者
    if(document.all)
    document.getElementById('div1').attachEvent('onclick',show);
    else
    document.getElementById('div1').addEventListener('click',show,false);
    这都是DOM2机智.
    传递参数不同的
    你去理解下DOM2事件下冒泡和捕获事件,以及DOM0与DOM2 的优缺点.
    .DOM0与DOM2 事件方法this 指向是不同的.是怎么回事情就明白了.加油吧,