瀏覽器相容問題處理總結

2021-09-24 08:06:31 字數 2668 閱讀 2181

解決方法

var str = ''

// 1. json.parse : 將json格式的字串轉成json格式的物件

/*var o = json.parse(str);

o.a=200;//

console.log(o.a);

console.log(json);*/

//在ie8以下,json是不存在的

console.log(eval("("+str+")"))

複製**

function getbrother(curele) 

pre = pre.previoussibling;

// pre等於哥哥節點的哥哥節點;}}

複製**

function.prototype.mybind = function

() }

複製**

var winw=document.body.clientwidth

var winh=document.body.clientheight

複製**

document.documentelement.clientwidth||docuemnt.body.clientwidth

document.documentelement.clientheight||docuemnt.body.clientheight

複製**

解決方法
元素.currentstyle.屬性名 //相容ie所有瀏覽器

//只能ie使用

複製**

解決方法:
function getclassnames(classstr,tagname)else 

}return ret;}}

function hasclass(tagstr,classstr)

}return

false ;

}複製**

解決方法:
//ie支援

attachevent("onclick",fn)

//事件需加上on

複製**

attachevent繫結的事件方法順序是倒序的

重複繫結的問題:可以給同乙個元素的同乙個事件繫結相同的方法

ie8以上既有addeventlistener又有attachevent

函式方法中的this指向window,不指向被繫結的那個元素

box.attachevent("onclick",fn);

box.attachevent("onclick",fn);

複製**

box.onclick=function(e)

console.log(e) //ie下undefined

複製**

解決方法:
console.log(window.event);

e=e||window.event;

複製**

1. 事件物件裡沒有pagex
box.onclick = function (e) 

複製**

2. 事件物件裡沒有pagey
box.onclick = function (e) 

複製**

3. 事件物件裡沒有target
box.onclick = function (e) 

複製**

無法使用事件物件裡的preventdefault( )

可以更改returnvalue的屬性值為false,同樣可以阻止事件預設行為

//相容瀏覽器

元素.onclick = function(e)

console.log(e);

複製**

無法使用e.stoppropagation( )

阻止事件的冒泡傳播: e.stoppropagation()

解決方法:

//ie8及以下就沒有這個e

元素.onclick = function (e)

e.stoppropagation();

console.log("center")

}複製**

注意:

要解綁(不然點上就出不來了)!

谷歌及其他瀏覽器不能使用!

function

up() else

}複製**

foreach在ie8中不相容,重寫該方法
if ( !array.prototype.foreach ) 

var o = object(this);

var len = o.length >>> 0;

if ( typeof callback !== "function" )

if ( arguments.length > 1 )

k = 0;

while( k < len )

k++;}};

}複製**

解決方法:指令碼實現ie8相容

解決方法: ie8下需要分開寫

未完待更新!

瀏覽器相容問題總結

一 dom篇 ie中所有的dom物件都是又com物件的形式實現的,ie不能訪問node型別,dom中每個節點的nodetyoe屬性 元素 屬性 文字 對應com中的數值 1,2,3 ie和其他瀏覽器對自定義屬性的查詢結果不同 e在解析節點的過程中不會包括空白節點,使用childnodes遍歷節點的過...

瀏覽器相容問題總結

html js css html一般是舊的瀏覽器版本不相容新的瀏覽器的新特性 js 中事件流dom2級事件,1 非ie瀏覽器新增事件 dom.addeventlistener click function true dom.removeeventlistener ie瀏覽器新增事件 dom.atta...

瀏覽器相容問題總結

1 jquery 2.0不再對ie6 7 8三個版本進行支援。如果你的 需要維護對ie8或者低版本 或者是ie9和ie10在相容模式下執行 你只需要沿用jquery1.9或者以下版本。2 如果使用springmvc風格的話,ie11有時候會將 userid 這種url引數中的 和 進行轉意成 3f和...