栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > Web开发 > JavaScript

jQuery选择器源码解读(四):tokenize方法的Expr.preFilter

JavaScript 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

jQuery选择器源码解读(四):tokenize方法的Expr.preFilter

Expr.preFilter是tokenize方法中对ATTR、CHILD、PSEUDO三种选择器进行预处理的方法。具体如下:

Expr.preFilter : {
	"ATTR" : function(match) {
		
		match[1] = match[1].replace(runescape, funescape);

		
		match[3] = (match[4] || match[5] || "").replace(runescape,
				funescape);

		
		if (match[2] === "~=") {
			match[3] = " " + match[3] + " ";
		}

		
		return match.slice(0, 4);
	},

	"CHILD" : function(match) {
		
		match[1] = match[1].toLowerCase();

		
		if (match[1].slice(0, 3) === "nth") {
			
			if (!match[3]) {
				Sizzle.error(match[0]);
			}
			
			match[4] = +(match[4] ? match[5] + (match[6] || 1)
					: 2 * (match[3] === "even" || match[3] === "odd"));
			match[5] = +((match[7] + match[8]) || match[3] === "odd");

		} else if (match[3]) {
			
			Sizzle.error(match[0]);
		}

		return match;
	},

	"PSEUDO" : function(match) {
		
		var excess, unquoted = !match[5] && match[2];

		
		if (matchExpr["CHILD"].test(match[0])) {
			return null;
		}
		
		if (match[3] && match[4] !== undefined) {
			match[2] = match[4];
		} else if (unquoted
				
				&& rpseudo.test(unquoted)
				&&
				
				(excess = tokenize(unquoted, true))
				&&
				
				(excess = unquoted.indexOf(")", unquoted.length
						- excess)
						- unquoted.length)) {

			// 获取有效的完整伪类match[0]和伪类括号内的数据match[2]
			match[0] = match[0].slice(0, excess);
			match[2] = unquoted.slice(0, excess);
		}

		// 返回match前三个元素的副本
		return match.slice(0, 3);
	}
}

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/103254.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号