firefox瀏覽器window.event is undefined問題


獲取鼠標坐標,IE下window.event.clientX和window.event.clientY就可以獲取x,y的座標了。但是firefox卻不行,瀏覽器報錯window.event is undefined! 

加了一段代碼解決!

var evt = window.event || arguments.callee.caller.arguments[0];

測試

if (typeof (window.evt) == 'undefined') 
alert('window.event is undefined.'); 
else 
alert('window.event is defined.'); 

alert彈框彈出window.event is defined!

//firefox
$j("#popcol").css("left",evt.pageX + window.document.body.scrollLeft-20);
$j("#popcol").css("top",evt.pageY + window.document.body.scrollTop-20);

這樣就獲取到x,y的座標了,還有個問題就是:firefox獲取坐標是pageX、pageY;IE獲取坐標是clientX、clientY;

開發過程中遇到的問題,不是職業寫前端的,記錄一下遇到的問題


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM