日期:2014-05-16  浏览次数:20395 次

Js杂记-1
1、compareDocumentPosition返回值
【父】【子】【前】【后】【非同一文档】
匹配为1,反之为0。相等是00000

var contains = document.compareDocumentPosition ? function(a, b){
	return !!(a.compareDocumentPosition(b) & 16);
} : function(a, b){
	return a !== b && (a.contains ? a.contains(b) : true);
};


2、nodeType
1-ELEMENT
2-ATTRIBUTE
3-TEXT
4-CDATA
5-ENTITY REFERENCE
6-ENTITY
7-PI (processing instruction)
8-COMMENT
9-DOCUMENT
10-DOCUMENT TYPE
11-DOCUMENT FRAGMENT
12-NOTATION

3、最近看jquery的sizzle
var chunker = /((?:\((?:\([^()]+\)|[^()]+)+\)|\[(?:\[[^[\]]*\]|['"][^'"]*['"]|[^[\]'"]+)+\]|\\.|[^ >+~,(\[\\]+)+|[>+~])(\s*,\s*)?((?:.|\r|\n)*)/g,

拆分第一步
((?:\((?:\([^()]+\)|[^()]+)+\)|\[(?:\[[^[\]]*\]|['"][^'"]*['"]|[^[\]'"]+)+\]|\\.|[^ >+~,(\[\\]+)+|[>+~])
(\s*,\s*)?
((?:.|\r|\n)*)

再细分一下最长的
(
	(?:
		\((?:\([^()]+\)|[^()]+)+\)
		|
		\[(?:\[[^[\]]*\]|['"][^'"]*['"]|[^[\]'"]+)+\]
		|
		\\.
		|
		[^ >+~,(\[\\]+
	)+
|
	[>+~]
)