jQuery源码解读之removeAttr()方法分析(2)

jQuery.extend({
    propFix: {
        "for": "htmlFor",
        "class": "className"
    }
});
jQuery.extend({
    camelCase: function( string ) {
        return string.replace( rmsPrefix, "ms-" ).replace( rdashAlpha, fcamelCase );
    }
});
var nodeHook, boolHook,
    attrHandle = jQuery.expr.attrHandle,
    ruseDefault = /^(?:checked|selected)$/i,
    getSetAttribute = support.getSetAttribute,
    getSetInput = support.input;
// Setup
div = document.createElement( "div" );
div.setAttribute( "className", "t" );
div.innerHTML = "  <link/><table></table><a href='https://www.jb51.net/a'>a</a><input type='checkbox'/>";
a = div.getElementsByTagName("a")[ 0 ];
// First batch of tests.
select = document.createElement("select");
opt = select.appendChild( document.createElement("option") );
input = div.getElementsByTagName("input")[ 0 ];
a.style.cssText = "top:1px";
// Test setAttribute on camelCase class. If it works, we need attrFixes when doing get/setAttribute (ie6/7)
support.getSetAttribute = div.className !== "t";

检测input是否支持getAttribute("value")

复制代码 代码如下:

// Support: IE8 only
// Check if we can trust getAttribute("value")
input = document.createElement( "input" );
input.setAttribute( "value", "" );
support.input = input.getAttribute( "value" ) === "";

检测是否布尔值属性

复制代码 代码如下:

booleans = "checked|selected|async|autofocus|autoplay|controls|defer|disabled|hidden|ismap|loop|multiple|open|readonly|required|scoped",

matchExpr = {
    "bool": new RegExp( "^(?:" + booleans + ")$", "i" )
},

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wgfjxx.html