jQuery浏览器功能测试support

浏览器功能测试模块是其他模块的基础。
一般解决浏览器不兼容问题有两种方式:浏览器嗅觉和浏览器功能测试。
jQuery.support 有34个测试项,包括DOM测试(15个),样式测试(3个),事件测试(4个),Ajax测试(2个),盒模型测试(10个)

查看测试项的结果:

<!DOCTYPE html>
<html lang="en">
<head>
     <meta charset="UTF-8">
     <title>Document</title>
</head>
<body>
<div id="release"></div>
<script type="text/javascript" src="jquery-1.7.1.js"></script>    
<script type="text/javascript">
$(function(){
     var result = '', counter = 0;
     for (var n in $.support){
          result += '<li>' + n +":"+$.support[n] + "</li>";
     }

     $("#release").html('<ol>'+result + '<ol>');
});
</script>
</body>
</html>


* leadingWhitespace:true
* tbody:true
* htmlSerialize:true
* style:true
* hrefNormalized:true
* opacity:true
* cssFloat:true
* checkOn:true
* optSelected:true
* getSetAttribute:true
* enctype:true
* html5Clone:true
* submitBubbles:true
* changeBubbles:true
* focusinBubbles:false
* deleteExpando:true
* noCloneEvent:true
* inlineBlockNeedsLayout:false
* shrinkWrapBlocks:false
* reliableMarginRight:true
* noCloneChecked:true
* optDisabled:true
* radioValue:true
* checkClone:true
* appendChecked:true
* ajax:true
* cors:true
* reliableHiddenOffsets:true
* boxModel:true
* doesNotAddBorder:true
* doesAddBorderForTableAndCells:true
* fixedPosition:true
* subtractsBorderForOverflowNotVisible:false
* doesNotIncludeMarginInBodyOffset:true

总体结构

jQuery.support = (function() {
     var support,
     support = {
          // IE strips leading whitespace when .innerHTML is used
          leadingWhitespace: ( div.firstChild.nodeType === 3 ),

          // Make sure that tbody elements aren't automatically inserted
          // IE will insert them into empty tables
          tbody: !div.getElementsByTagName("tbody").length,

          // Make sure that link elements get serialized correctly by innerHTML
          // This requires a wrapper element in IE
          htmlSerialize: !!div.getElementsByTagName("link").length,

          // Get the style information from getAttribute
          // (IE uses .cssText instead)
          style: /top/.test( a.getAttribute("style") ),

          // Make sure that URLs aren't manipulated
          // (IE normalizes it by default)
          hrefNormalized: ( a.getAttribute("href") === "/a" ),

          // Make sure that element opacity exists
          // (IE uses filter instead)
          // Use a regex to work around a WebKit issue. See #5145
          opacity: /^0.55/.test( a.style.opacity ),

          // Verify style float existence
          // (IE uses styleFloat instead of cssFloat)
          cssFloat: !!a.style.cssFloat,

          // Make sure that if no value is specified for a checkbox
          // that it defaults to "on".
          // (WebKit defaults to "" instead)
          checkOn: ( input.value === "on" ),

          // Make sure that a selected-by-default option has a working selected property.
          // (WebKit defaults to false instead of true, IE too, if it's in an optgroup)
          optSelected: opt.selected,

          // Test setAttribute on camelCase class. If it works, we need attrFixes when doing get/setAttribute (ie6/7)
          getSetAttribute: div.className !== "t",

          // Tests for enctype support on a form(#6743)
          enctype: !!document.createElement("form").enctype,

          // Makes sure cloning an html5 element does not cause problems
          // Where outerHTML is undefined, this still works
          html5Clone: document.createElement("nav").cloneNode( true ).outerHTML !== "<:nav></:nav>",

          // Will be defined later
          submitBubbles: true,
          changeBubbles: true,
          focusinBubbles: false,
          deleteExpando: true,
          noCloneEvent: true,
          inlineBlockNeedsLayout: false,
          shrinkWrapBlocks: false,
          reliableMarginRight: true
     };

     support.noCloneChecked = input.cloneNode( true ).checked;
     support.optDisabled = !opt.disabled;
     support.deleteExpando = false;
     ....

     jQuery(function() {

          support.reliableHiddenOffsets = isSupported && ( tds[ 0 ].offsetHeight === 0 );
          ...
          jQuery.extend( support, offsetSupport );
     });

     (function(){
          jQuery.extend(jQuery.support, {
               ajax: !!xhr,
               cors: !!xhr && ("withCredentials" in xhr)
          });
     });
     return support;
})();
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值