IE6,IE7,IE8,IE9,chrome 23.0.1271.95,firefox 17.0.1,其中IE78是在IE9的文档模式下,不包准确,但jQuery和网上搜到的结果应该可以相信前人的测试是准确的。
a";
//Supporttestswon'truninsomelimitedornon-browserenvironments
all=div.getElementsByTagName("*");
a=div.getElementsByTagName("a")[0];
if(!
all||!
a||!
all.length){
return{};
}
//Firstbatchoftests
select=document.createElement("select");
opt=select.appendChild(document.createElement("option"));
input=div.getElementsByTagName("input")[0];
a.style.cssText="top:
1px;float:
left;opacity:
.5";
support={
//IEstripsleadingwhitespacewhen.innerHTMLisused
//IE678的childNodes不包含空白文本节点,firstChild同理
leadingWhitespace:
(div.firstChild.nodeType===3),
//Makesurethattbodyelementsaren'tautomaticallyinserted
//IEwillinsertthemintoemptytables
//空table,IE会自动生成tbody,而标准浏览器不会(标准浏览器如果有tr存在,也会自动生成tbody)
tbody:
!
div.getElementsByTagName("tbody").length,
//MakesurethatlinkelementsgetserializedcorrectlybyinnerHTML
//ThisrequiresawrapperelementinIE
//IE678无法通过div.innerHTML='';来插入link
htmlSerialize:
!
!
div.getElementsByTagName("link").length,
//GetthestyleinformationfromgetAttribute
//(IEuses.cssTextinstead)
//IE67无法用getAttribute获取style,返回object,同理也无法用setAttribute设置style
style:
/top/.test(a.getAttribute("style")),
//MakesurethatURLsaren'tmanipulated
//(IEnormalizesitbydefault)
//getAttribute获取href的问题,详见
hrefNormalized:
(a.getAttribute("href")==="/a"),
//Makesurethatelementopacityexists
//(IEusesfilterinstead)
//UsearegextoworkaroundaWebKitissue.See#5145
//IE678是通过filter滤镜来支持透明度
opacity:
/^0.5/.test(a.style.opacity),
//Verifystylefloatexistence
//(IEusesstyleFloatinsteadofcssFloat)
//IE678通过styleFloat来获取float,而标准浏览器用cssFloat
cssFloat:
!
!
a.style.cssFloat,
//Makesurethatifnovalueisspecifiedforacheckbox
//thatitdefaultsto"on".
//(WebKitdefaultsto""instead)
//checkbox的默认值为'on',chrome 23.0.1271.95m测试
checkOn:
(input.value==="on"),
//Makesurethataselected-by-defaultoptionhasaworkingselectedproperty.
//(WebKitdefaultstofalseinsteadoftrue,IEtoo,ifit'sinanoptgroup)
//IE中,第一个option不被默认选中,包括IE9依然如此,其他则选中
optSelected:
opt.selected,
//TestsetAttributeoncamelCaseclass.Ifitworks,weneedattrFixeswhendoingget/setAttribute(ie6/7)
//IE67无法通过setAttribute('class','ooxx')来设置className(IE67支持setAttribute('className','ooxx'
)),其他浏览器则可以,反之getAttribute同理
getSetAttribute:
div.className!
=="t",
//Testsforenctypesupportonaform(#6743)
//本机所有浏览器支持一样ie6789,chrome,ff
enctype:
!
!
document.createElement("form").enctype,
//Makessurecloninganhtml5elementdoesnotcauseproblems
//WhereouterHTMLisundefined,thisstillworks
//IE6在克隆HTML5的新标签元素时outerHTML有":
"
html5Clone:
document.createElement("nav").cloneNode(true).outerHTML!
=="<:
nav>
nav>",
//jQuery.support.boxModelDEPRECATEDin1.8sincewedon'tsupportQuirksMode
//检测诡异模式,也就是IE6没有doctype时的模式
boxModel:
(patMode==="CSS1Compat"),
//Willbedefinedlater
submitBubbles:
true,
changeBubbles:
true,
focusinBubbles:
false,
deleteExpando:
true,
noCloneEvent:
true,
inlineBlockNeedsLayout:
false,
shrinkWrapBlocks:
false,
reliableMarginRight:
true,
boxSizingReliable:
true,
pixelPosition:
false
};
//Makesurecheckedstatusisproperlycloned
//IE6789,checked不能被拷贝
input.checked=true;
support.noCloneChecked=input.cloneNode(true).checked;
//Makesurethattheoptionsinsidedisabledselectsaren'tmarkedasdisabled
//(WebKitmarksthemasdisabled)
//chrome23已修复
select.disabled=true;
support.optDisabled=!
opt.disabled;
//Testtoseeifit'spossibletodeleteanexpandofromanelement
//FailsinInternetExplorer
//IE678不能delete节点上的属性
try{
deletediv.test;
}catch(e){
support.deleteExpando=false;
}
//IE会拷贝事件
if(!
div.addEventListener&&div.attachEvent&&div.fireEvent){
div.attachEvent("onclick",clickFn=function(){
//Cloninganodeshouldn'tcopyoverany
//boundeventhandlers(IEdoesthis)
support.noCloneEvent=false;
});
div.cloneNode(true).fireEvent("onclick");
div.detachEvent("onclick",clickFn);
}
//Checkifaradiomaintainsitsvalue
//afterbeingappendedtotheDOM
//IE下,input被更换类型后,无法保持前一个类型所设的值,蛋疼
input=document.createElement("input");
input.value="t";
input.setAttribute("type","radio");
support.radioValue=input.value==="t";
input.setAttribute("checked","checked");
//#11217-WebKitlosescheckwhenthenameisafterthecheckedattribute
//chrome23已修复
input.setAttribute("name","t");
div.appendChild(input);
fragment=document.createDocumentFragment();
fragment.appendChild(div.lastChild);
//WebKitdoesn'tclonecheckedstatecorrectlyinfragments
//chrome23已修复
support.checkClone=fragment.cloneNode(true).cloneNode(true).lastChild.checked;
//Checkifadisconnectedcheckboxwillretainitschecked
//valueoftrueafterappendedtotheDOM(IE6/7)
support.appendChecked=input.checked;
fragment.removeChild(input);
fragment.appendChild(div);
//TechniquefromJuriyZaytsev
//
//Weonlycareaboutthecasewherenon-standardeventsystems
//areused,namelyinIE.Short-circuitingherehelpsusto
//avoidanevalcall(insetAttribute)whichcancauseCSP
//togohaywire.See:
https:
//developer.mozilla.org/en/Security/CSP
//检测事件类型,如果上面的英文文章看不懂,推荐看这篇:
if(div.attachEvent){
for(iin{
submit:
true,
change:
true,
focusin:
true
}){
eventName="on"+i;
isSupported=(eventNameindiv);
if(!
isSupported){
div.setAttribute(eventName,"return;");
isSupported=(typeofdiv[eventName]==="function");
}
su