日期:2014-05-16  浏览次数:20362 次

怎么在firefox中实现style.pixelTop和style.pixelLeft
 
  document.oncontextmenu=function() { 

mlay.style.display=""; 
mlay.style.pixelTop=event.clientY; 
mlay.style.pixelLeft=event.clientX; 
return false; 

   
  这是一个发生右键事件时来控制一个DIV
<div id="mlay" style="position: absolute; display: none; cursor: default;"onClick="return false;"></div>

带代码只在ie中有效,请问怎么能兼容firefox呢?

------解决方案--------------------
HTML code
<div id="mlay" style="position: absolute; display: none; cursor: default;"onClick="return false;">菜单</div>
<script type="text/javascript">

    document.oncontextmenu = function (event) {
        var mlay = document.getElementById('mlay');
        mlay.style.display = "";
        event = event || window.event;
        mlay.style.top = event.clientY + 'px';
        mlay.style.left = event.clientX + 'px';
        return false;
    }  </script>