整理的比較全的event對像在ie與firefox瀏覽器中的區(qū)別
更新時間:2013年11月25日 17:02:58 作者:
event對像在IE與FF中的區(qū)別,本文整理了很多,個人感覺還是比較全面的,需要的朋友可以收藏下
window.event
IE:有window.event對象
FF:沒有window.event對象??梢酝ㄟ^給函數(shù)的參數(shù)傳遞event對象。如onmousemove=doMouseMove(event)
鼠標(biāo)當(dāng)前坐標(biāo)
IE:event.x和event.y。
FF:event.pageX和event.pageY。
通用:兩者都有event.clientX和event.clientY屬性。
鼠標(biāo)當(dāng)前坐標(biāo)(加上滾動條滾過的距離)
IE:event.offsetX和event.offsetY。
FF:event.layerX和event.layerY。
標(biāo)簽的x和y的坐標(biāo)位置:style.posLeft 和 style.posTop
IE:有。
FF:沒有。
通用:object.offsetLeft 和 object.offsetTop。
窗體的高度和寬度
IE:document.body.offsetWidth和document.body.offsetHeight。注意:此時頁面一定要有body標(biāo)簽。
FF:window.innerWidth和window.innerHegiht,以及document.documentElement.clientWidth和document.documentElement.clientHeight。
通用:document.body.clientWidth和document.body.clientHeight。
添加事件
IE:element.attachEvent(”onclick”, func);。
FF:element.addEventListener(”click”, func, true)。
通用:element.onclick=func。雖然都可以使用onclick事件,但是onclick和上面兩種方法的效果是不一樣的,onclick只有執(zhí)行一個過程,而attachEvent和addEventListener執(zhí)行的是一個過程列表,也就是多個過程。例如:element.attachEvent(”onclick”, func1);element.attachEvent(”onclick”, func2)這樣func1和func2都會被執(zhí)行。
標(biāo)簽的自定義屬性
IE:如果給標(biāo)簽div1定義了一個屬性value,可以div1.value和div1[”value”]取得該值。
FF:不能用div1.value和div1[”value”]取。
通用:div1.getAttribute(”value”)。
父節(jié)點(diǎn)、子節(jié)點(diǎn)和刪除節(jié)點(diǎn)
IE:parentElement、parement.children,element.romoveNode(true)。
FF:parentNode、parentNode.childNodes,node.parentNode.removeChild(node)。
IE:有window.event對象
FF:沒有window.event對象??梢酝ㄟ^給函數(shù)的參數(shù)傳遞event對象。如onmousemove=doMouseMove(event)
鼠標(biāo)當(dāng)前坐標(biāo)
IE:event.x和event.y。
FF:event.pageX和event.pageY。
通用:兩者都有event.clientX和event.clientY屬性。
鼠標(biāo)當(dāng)前坐標(biāo)(加上滾動條滾過的距離)
IE:event.offsetX和event.offsetY。
FF:event.layerX和event.layerY。
標(biāo)簽的x和y的坐標(biāo)位置:style.posLeft 和 style.posTop
IE:有。
FF:沒有。
通用:object.offsetLeft 和 object.offsetTop。
窗體的高度和寬度
IE:document.body.offsetWidth和document.body.offsetHeight。注意:此時頁面一定要有body標(biāo)簽。
FF:window.innerWidth和window.innerHegiht,以及document.documentElement.clientWidth和document.documentElement.clientHeight。
通用:document.body.clientWidth和document.body.clientHeight。
添加事件
IE:element.attachEvent(”onclick”, func);。
FF:element.addEventListener(”click”, func, true)。
通用:element.onclick=func。雖然都可以使用onclick事件,但是onclick和上面兩種方法的效果是不一樣的,onclick只有執(zhí)行一個過程,而attachEvent和addEventListener執(zhí)行的是一個過程列表,也就是多個過程。例如:element.attachEvent(”onclick”, func1);element.attachEvent(”onclick”, func2)這樣func1和func2都會被執(zhí)行。
標(biāo)簽的自定義屬性
IE:如果給標(biāo)簽div1定義了一個屬性value,可以div1.value和div1[”value”]取得該值。
FF:不能用div1.value和div1[”value”]取。
通用:div1.getAttribute(”value”)。
父節(jié)點(diǎn)、子節(jié)點(diǎn)和刪除節(jié)點(diǎn)
IE:parentElement、parement.children,element.romoveNode(true)。
FF:parentNode、parentNode.childNodes,node.parentNode.removeChild(node)。
相關(guān)文章
使用JavaScript解決網(wǎng)頁圖片拉伸問題(推薦)
本文給大家介紹使用javascript解決網(wǎng)頁圖片拉伸問題,本文給大家介紹的非常詳細(xì),具有參考借鑒價值,感興趣的朋友一起看看吧2016-11-11javascript結(jié)合Cookies實現(xiàn)瀏覽記錄歷史
最近在工作當(dāng)中遇到一個問題 有個頁面需要添加一個瀏覽歷史記錄功能,具體來說就是要記錄下用戶在此網(wǎng)站的點(diǎn)擊歷史 并把它們降序排列出來(只顯示前6個瀏覽歷史而且不能重復(fù))。2008-09-09javascript setTimeout和setInterval計時的區(qū)別詳解
window對象有兩個主要的定時方法,分別是setTimeout 和 setInteval 他們的語法基本上相同,但是完成的功能取有區(qū)別。2013-06-06