当前位置: 代码迷 >> JavaScript >> Js传记-1
  详细解决方案

Js传记-1

热度:107   发布时间:2012-10-26 10:30:59.0
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)*)

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