博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
jquery源码03 (3184 , 3295) support : 功能检测
阅读量:6194 次
发布时间:2019-06-21

本文共 4793 字,大约阅读时间需要 15 分钟。

无标题文档
//兼容性,support是做兼容性检测,检测完之后实施是通过钩子机制。jQuery.support = (function( support ) {
//右边函数会立即执行 var input = document.createElement("input"), fragment = document.createDocumentFragment(),//文档碎片 div = document.createElement("div"), select = document.createElement("select"), opt = select.appendChild( document.createElement("option") ); // input.type默认是text,基本都有, if ( !input.type ) { return support; } //改成复选框 input.type = "checkbox"; //新版本value的值是'on',老版本value的值是'',所以新本版support.checkOn=true,老版本support.checkOn=false,就可以通过support.checkOn属性值进行浏览器类型判断。 support.checkOn = input.value !== ""; // 狐火chrome下拉子项默认是选中的,ie默认不选中。 support.optSelected = opt.selected; // 定义初始值 support.reliableMarginRight = true; support.boxSizingReliable = true; support.pixelPosition = false; // Make sure checked status is properly cloned // Support: IE9, IE10 //先让input选中,然后克隆,再判断选中状态,火狐chromeIE10以上都是选中的,ie低版本不是选中。 input.checked = true; support.noCloneChecked = input.cloneNode( true ).checked; // Make sure that the options inside disabled selects aren't marked as disabled // (WebKit marks them as disabled) //下拉菜单禁止,子项有没有禁止。 select.disabled = true; support.optDisabled = !opt.disabled; // Check if an input maintains its value after becoming a radio // Support: IE9, IE10 input = document.createElement("input"); input.value = "t"; input.type = "radio"; support.radioValue = input.value === "t"; // #11217 - WebKit loses check when the name is after the checked attribute input.setAttribute( "checked", "t" ); input.setAttribute( "name", "t" ); fragment.appendChild( input ); // Support: Safari 5.1, Android 4.x, Android 2.3 // old WebKit doesn't clone checked state correctly in fragments support.checkClone = fragment.cloneNode( true ).cloneNode( true ).lastChild.checked; // Support: Firefox, Chrome, Safari // Beware of CSP restrictions (https://developer.mozilla.org/en/Security/CSP) support.focusinBubbles = "onfocusin" in window; //首先定义一个div的背景剪切是内容剪切,然后复制一份设置背景剪切为空,然后看原来div的背景剪切还是不是内容剪切。 div.style.backgroundClip = "content-box"; div.cloneNode( true ).style.backgroundClip = ""; support.clearCloneStyle = div.style.backgroundClip === "content-box"; //下面的需要等dom加载完才能检测 jQuery(function() { var container, marginDiv, // Support: Firefox, Android 2.3 (Prefixed box-sizing versions). // divReset = "padding:0;margin:0;border:0;display:block;-webkit-box-sizing:content-box;-moz-box-sizing:content-box;box-sizing:content-box", body = document.getElementsByTagName("body")[ 0 ]; if ( !body ) { // Return for frameset docs that don't have a body return; } //创建一个container来检测 container = document.createElement("div"); container.style.cssText = "border:0;width:0;height:0;position:absolute;top:0;left:-9999px;margin-top:1px"; // Check box-sizing and margin behavior. body.appendChild( container ).appendChild( div ); div.innerHTML = ""; // Support: Firefox, Android 2.3 (Prefixed box-sizing versions). div.style.cssText = "-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box;padding:1px;border:1px;display:block;width:4px;margin-top:1%;position:absolute;top:1%"; // Workaround failing boxSizing test due to offsetWidth returning wrong value // with some non-1 values of body zoom, ticket #13543 jQuery.swap( body, body.style.zoom != null ? { zoom: 1 } : {}, function() { support.boxSizing = div.offsetWidth === 4; }); // Use window.getComputedStyle because jsdom on node.js will break without it. if ( window.getComputedStyle ) { support.pixelPosition = ( window.getComputedStyle( div, null ) || {} ).top !== "1%"; support.boxSizingReliable = ( window.getComputedStyle( div, null ) || { width: "4px" } ).width === "4px"; // Support: Android 2.3 // Check if div with explicit width and no margin-right incorrectly // gets computed margin-right based on width of container. (#3333) // WebKit Bug 13343 - getComputedStyle returns wrong value for margin-right marginDiv = div.appendChild( document.createElement("div") ); marginDiv.style.cssText = div.style.cssText = divReset; marginDiv.style.marginRight = marginDiv.style.width = "0"; div.style.width = "1px"; support.reliableMarginRight = !parseFloat( ( window.getComputedStyle( marginDiv, null ) || {} ).marginRight ); } body.removeChild( container ); }); return support;//返回json})( {} );//实参json

 

转载地址:http://wmuca.baihongyu.com/

你可能感兴趣的文章
python添加环境变量
查看>>
Linux 新手容易犯的 7 个错误
查看>>
spoj3105 MOD - Power Modulo Inverted(exbsgs)
查看>>
DP-01背包 (题)
查看>>
WinForm中跨线程操作控件
查看>>
CODING 敏捷实践完全指南
查看>>
unittest测试框架和测试报告的输出实例(一)
查看>>
PYTHON-字符编码
查看>>
collectionview 的相关设置
查看>>
【node.js】回调函数
查看>>
Phalcon 訪问控制列表 ACL(Access Control Lists ACL)
查看>>
Android Categroy 详解大全
查看>>
java中的定时器
查看>>
【翻译】EXTJS 编码风格指南与实例
查看>>
下MFC中对象、句柄、ID之间的区别.
查看>>
如何构建Win32汇编的编程环境(ONEPROBLEM个人推荐)
查看>>
Asp.Net MVC 分页、检索、排序整体实现
查看>>
php上传$_FILES 无法取值
查看>>
python 输出当前行号
查看>>
vue21 slot占位
查看>>