js在瀏覽器下的區別小結(部分)

來源:互聯網
上載者:User

標籤:

1.初始化數組:

document.write([1,2,3,].length);

IE:4//把數組中最後一個逗號後面的當做了undefined元素

FF、Opera、Safari:3

 

2.join數組原型:

當分隔字元為undefined時,IE會使用undefined作為分隔字元

例如:

var array=[1,2];

alert(array.join(","));

alert(array.join(undefined));

alert(array.join("-"));

IE:1,2

    1undefined2

    1-2

FF、Opera、Safari:1,2

                          1,2

                          1-2

 

3.valueof日期用法:

直接調用日期的valueof方法,IE將返回0,而其他將返回NaN

document.write(Date.prototype.valueof());

IE:0

FF、Opera、Safari:NaN

 

4.IE可直接使用event對象,其他不可以。

 

5.IE擷取事件目標用srcElement,其他的用event.target

 

6.擷取鍵盤值:

IE:event.keycode

非IE:event.which

 

7.擷取指標的絕對位置

IE:event.X event.Y

其他:event.PageX event.PageY

 

8.通過id訪問html元素

IE:可以使用eval("idname")或getElementById("idname");還支援將id作為document的屬性名稱直接使用,其他不支援

非IE:getElementById("idname");

 

9.IE訪問表單可以用document.form.item("itemname");或者document.formName.elements["elementName"];

非IE:document.formName.elements["elementName"];

 

10.刪除節點:

IE:removeNode()或找到父節點,用removeChild()

非IE:找到父節點,用removeChild()

 

11.交換節點:

IE:支援swapNode私人方法交換HTML

 

12.IE:window.location或者window.location.href

非IE:window.location

 

13.訪問父節點:

IE:obj.parentElement

FF:obj.parentNode

 

14.插入文本

IE:innerText

非IE:textContent

 

15.float值

IE:document.getElementById("idname").style.styleFloat="";

非IE:document.getElementById("idname").style.cssFloat="";

 

16.訪問類樣式

IE:getAttribute("classname");

非IE:getAttribute("class");

 

17.label和for屬性

IE:getAttribute("htmlFor");

非IE:getAttribute("for");

 

18.擷取滑鼠指標位置

IE:event.clientX event.clientY

非IE:event.PageX event.pageY

 

19.可去地區視窗大小

IE:document.documentElement.clientWidth  document.documentElement.clientWidth

非IE:window.innerWidth   window.innerHeight

 

20.尺寸

IE:obj.style.height=imgobj.height

非IE:obj.style.height=imgobj.height+"px"

js在瀏覽器下的區別小結(部分)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.