/*
code ref http://www.cnblogs.com/rubylouvre/archive/2009/10/14/1583523.html
IE有contains方法。如果A元素包含B元素,则返回true,否则false。唯一不支持这个方法的是firefox。
不过火狐支持compareDocumentPosition() 方法,这是W3C制定的方法,标准浏览器都支持。
它的使用形式与contains差不多,但返回的不是一个布尔值,而是一个很奇怪的数值,它是通过如下方式累加计算出来的:
二进制 数值 含义
000000 0 元素一致
000001 1 节点在不同的文档(或者一个在文档之外)
000010 2 节点 B 在节点 A 之前
000100 4 节点 A 在节点 B 之前
001000 8 节点 B 包含节点 A
010000 16 节点 A 包含节点 B
100000 32 浏览器的私有使用
A.compareDocumentPosition(B);//B与A不相连,B在A的后面,B被A包含 4+16 = 20
B.compareDocumentPosition(A);//A与B不相连,A在B的前面,A包含B 2+8 = 10
*/
//PPK给出如下解决方法。
if (window.Node && Node.prototype && !Node.prototype.contains) {
Node.prototype.contains = function (arg) {
return !!(this.compareDocumentPosition(arg) & 16);//位运算 小于16结果为0
}
}
//2011.9.24 by 司徒正美
var contains = function(root, el) {
if (root.compareDocumentPosition)
return root === el || !!(root.compareDocumentPosition(el) & 16);
if (root.contains && el.nodeType === 1) {
return root.contains(el) && root !== el;
}
//两种原生方法都不支持的话 -_-||| 递归吧
while ((el = el.parentNode))
if (el === root) return true;
return false;
}
分享到:
相关推荐
Contains numerous hands-on examples Explains implementation of real-time apps including Socket.IO and HTML5, and WebSockets Addresses practical Node.js advantages from specific design choices ...
自定义____js中contains方法
// if (node.contains(randint)) { // continue; // } else { // if (!linked.contains(new Integer(randint))) { // linked.add(new Integer(randint)); // } else if (node....
This repo contains a Docker image and instructions to run a node 8 app version in AWS Lambda with Apex Up
Design of Combinational Circuit
简单队列Node.js 的简单内存队列。 它可以被远程客户端访问。安装通过节点上的 npm: npm install simplequeue从您的程序中引用它: var simplequeue = require ( 'simplequeue' ) ;本地使用创建队列,放置和获取...
While conceptually simple, this programming model contains numerous subtleties and be- haviors that are de ned implicitly by the current Node.js implementation. This paper presents the rst ...
NW.js 可以让你直接在 DOM 上调用所有 Node.js 模块,相当于使用一种新的方法来编写 Web 应用。NW.js 的前身是 node-webkit 。... (suppose the current directory contains 'package.json') 标签:NWjs
node-html2enml 是一个 node.js 模块,用于将 HTML 转换为 Evernote ENML。 ...用法 ...从 node.js 脚本调用 html2enml 如下: ... // base_uri contains uri to be prepended to convert relative URLs to absolu
Beanstalk API 的 Node.js 包装器 这是一个正在进行的工作! 目前只有“获取”功能可用。 安装 npm install beanstalk 用法 // Create an API token: https://ACCOUNTNAME.beanstalkapp.com/access_tokens var bean...
├── /config/ # This directory contains all configuration files │ ├── /env/ # Environment depending configs go here in respective files │ ├── /routes/ # All api route declarations go here. ...
一个简单的 node.js 模块,有助于将命名参数添加到节点应用程序调用 安装 npm install named-argv 用法 您可以对命名参数使用“--”和“-”前缀: node myapp.js --opt1=value1 -opt2=value 您还可以传递未命名...
对于您的对象或数组,只需在末尾添加.contains()即可确定它们是否包含此类元素。 重要的是要注意,搜索也是区分大小写的。 目的 {"elm1": "one", "elm2": "two"}.contains("elm1") // true {"elm1": "one", "elm2...
Node.js中的SDK 安装 $ npm install china --save 例子 var china = require ( 'china' ) ; china . index . list ( 'year|month|season' , function ( err , indexs ) { // list all indexs here, // contains...
你好Node.JS中用于HelloMD.com的API客户端。安装要使用命令行工具安装最新的稳定版本:... then ( function ( res ) { // res returns the patient json} , function ( err ) { // err contains error information when
Contains ............................................................................................................................................... 22 GetEnumerator .................................
在去年的 DB 勒索事件之后, 不少的同学开始加强 Mongodb 的安全性, 其中一种办法就是设置复杂的密码. 那么如果设置的密码里包含一些如 ...下面小编给大家带来了Node.js Mongodb 密码特殊字符 @的解决方法,一起学习吧
使用和制作的Node.js行为测试框架。 测试步骤是通用的,因此您可以快速创建测试套件: Scenario : Open the search page and find products When I open the url "https://someurl.com/search" And I set the ...
守望者:node.js的服务监视器 什么是守望者? 值班人员监视服务器的运行状况(停机,正常运行时间,响应时间警告,平均响应时间等)。 ping类型可通过npm模块插入。 目前, http-head和http-contains可用。 在下面...
if(mixRect.contains(event.getLocation())){ this.hammer.position = parent.position; this.hammer.active = true; this.count++; this.txtCount.string = this.count; break; } } }, this); ...