jQuery浏览器功能测试support --样式测试

发布时间:2019-05-26 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了jQuery浏览器功能测试support --样式测试脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。

样式测试(2.1~2.3)3个

jQuery.support = (function() {

    var support,
        all,
        a,

        div = document.createElement( "div" ),
        documentElement = document.documentElement;

    // Preliminary tests
    div.setAttribute("className", "t");
    div.innerHTML = "   <link/><table></table><a href='/a' style='top:1px;float:left;opacity:.55;'>a</a><input type='checkbox'/>";

    all = div.getElementsByTagName( "*" );
    a = div.getElementsByTagName( "a" )[ 0 ];

    support = {
        // Get the style information from getAttribute
        // (IE uses .cssText instead)
        // 2.1 如果DOM元素内联样式可以通过DOM属性style直接访问,则测试项style为true
        // 在IE6, IE7,IE8中,需要通过style.cssText访问内联样式,此时测试项style为false, 而在其他浏览器重则为true
        style: /top/.test( a.getAttribute("style") ),


        // Make sure that element opacity exists
        // (IE uses filter instead)
        // Use a regex to work around a WebKit issue. See #5145
        // 2.2 如果浏览器支持样式opacity, 则测试项opacity为true
        // 在IE6, IE7, IE8中,不支持样式opacity, 需要用滤镜(alpha filters)代替,此时测试项opacity为false, 而在其他浏览器中则为true
        // 在Opera9.2以及之前的Opera浏览器中,a.style.opacity==="0.5"的结果为false,即认为Opera不迟滞样式Opacity, 而事实上是支持的。
        // jquery-1.2.js的写法:a.style.opacity==="0.5"
        // jquery-1.4.js的写法是: /^0.55$/.test(a.style.opacity)
        opacity: /^0.55/.test( a.style.opacity ),

        // Verify style float existence
        // (IE uses styleFloat instead of cssFloat)
        // 2.3 如果浏览器支持通过style.cssFloat访问样式float, 则测试项cssFloat为true
        // 在IE6,IE7, IE8中,需要通过style.styleFloat访问样式float,此时测试项cssFloat为false, 而在其他浏览器中则为true
        cssFloat: !!a.style.cssFloat,

    };




    return support;
})();

脚本宝典总结

以上是脚本宝典为你收集整理的jQuery浏览器功能测试support --样式测试全部内容,希望文章能够帮你解决jQuery浏览器功能测试support --样式测试所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。