上一節我們處理分組選擇器,這次我們看看剩余的2種處理情況。
關系處理器處理
在層級關系中有幾種特殊的劃分 Token : >, +, 空格, ~ 用來表明:父與子,兄弟,祖輩子孫之間的層級關系。
selector = 'div.aaron,div > p'
從 > 劃分
rcombinators = new RegExp( "^" + whitespace + "*([>+~]|" + whitespace + ")" + whitespace + "*" )
可以是>+~
或者空白
這個分組是為了之后的關系選擇確定。
if ( (match = rcombinators.exec( soFar )) ) { matched = match.shift(); tokens.push({ value: matched, // Cast descendant combinators to space type: match[0].replace( rtrim, " " ) }); soFar = soFar.slice( matched.length ); }
元素的匹配器:
Expr.filter :TAG, ID, CLASS, ATTR, CHILD, PSEUDO
通過一系列的正則抽出表達式中的內容。
ID:
///^#((?:\\.|[\w-] | [^\x00-\xa0] ) +)/ var characterEncoding = "(?:\\\\.|[\\w-]|[^\\x00-\\xa0])+"; var ID = new RegExp("^#(" + characterEncoding + ")")
TAG:
var TAG = new RegExp( "^(" + characterEncoding.replace( "w", "w*" ) + ")" );
CLASS:
var Class = new RegExp( "^\\.(" + characterEncoding + ")" );
ATTR:
屬性選擇器有點復雜,通過第一次正則只能匹配器出整體,所以需要第二次分解,引入了Expr.preFilter,Expr.preFilter保留了3個兼容處理分別是ATTR,CHILD,PSEUDO復雜的選擇器。
var identifier = characterEncoding.replace( "w", "w#" ); var attributes = "\\[" + whitespace + "*(" + characterEncoding + ")(?:" + whitespace + // Operator (capture 2) "*([*^$|!~]?=)" + whitespace + // "Attribute values must be CSS identifiers [capture 5] or strings [capture 3 or capture 4]" "*(?:'((?:\\\\.|[^\\\\'])*)'|\"((?:\\\\.|[^\\\\\"])*)\"|(" + identifier + "))|)" + whitespace + "*\\]"; var ATTR = new RegExp( "^" + attributes ); preFilter: { "ATTR": function( match ) { match[1] = match[1].replace( runescape, funescape ); // Move the given value to match[3] whether quoted or unquoted match[3] = ( match[3] || match[4] || match[5] || "" ).replace( runescape, funescape ); if ( match[2] === "~=" ) { match[3] = " " + match[3] + " "; } return match.slice( 0, 4 ); }
請驗證,完成請求
由于請求次數過多,請先驗證,完成再次請求
打開微信掃碼自動綁定
綁定后可得到
使用 Ctrl+D 可將課程添加到書簽
舉報