标签:2.4 scrollto 高级 移动 container toe height ctc case
在DOM1的基础上进行扩展,引入更多的交互,并处理更高级的XML。分为许多应用的模块,对DOM2和DOM3的功能等进行描述,内容包括:DOM2级核心、DOM2级视图(view)、DOM2级事件(13章讨论)、DOM2级样式、DOM2级遍历和范围、DOM2级HTML、DOM3级增加了XPath模块和加载与保存模块,在Chapter18中讨论。本章讨论:
var supportsDOM2Core = document.implementation.hasFeatrue("Core","2.0"); var supportsDOM3Core = document.implementation.hasFeatrue("Core", "3.0); var supportsDOM2HTML = document.implementation.hasFeatrue("HTML","3.0); var supportsDOM2Views = document.implementation.hasFeatrue("Views", "2.0"); var supportsDOM2XML = document.implementation.hasFeatrue("XML", "2.0);
var supportsDom2CSS = document.implementation.hasFeature("CSS","2.0"); var supportsDOM2CSS2 = document.implementation.hasFeatrue("CSS2", "2.0");
var supportsTraversals = document.implementation.hasFeature("Traversal","2.0"); var supportsNodeIterator = (typeof document.createNodeIterator == ‘function‘); var supportsTreeWalker = (typeof document.createTreeWalker == ‘function‘);
var filter = { acceptNode: function(node){ return node.tagName.toLowerCase() == "p"? NodeFilter.FILTER_ACCEPT: NodeFilter.FILTER_SKIP; } };
<div id = "div1"> <p><b>Hello</b> world!</p> <ul> <li>List item 1</li> <li>List item 2</li> <li>List item 3</li> </ul> </div>
var div = document.getElementById("div1"); var walker = document.createTreeWalker(div, NodeFilter_SHOW_ELEMENT, null, false); walker.firstChild(); //转到<p> walker.nextSibling();//转到<ul> waler.firstChild(); //转到第一个<li>
var supportsRange = document.implementation.hasFeature("Range","2.0"); var alsoSupportsRange = (typeof document.createRange == "function");
<div id = "div1"> <p><b>Hello</b> world!</p> <ul> <li>List item 1</li> <li>List item 2</li> <li>List item 3</li> </ul> </div>
var range1 = document.createRange(); var range2 = document.createRange(); var p1 = document.getElementById("p1"); range1.selectNode(p1); range2.selectNodeContents(p1);
Range1使用selectNode()进行范围选择,则其startContainer/endContainer/commonAncestorContainer都是元素<p>的父节点document.body(commonAncestorContainer应该满足:共同的、最深的)。startOffset等于给定节点<p>在父元素childNodes中的位置索引1(考虑到DOM将前面的空格视作0)。endOffset等于startOffset+1(因为只选择了一个节点)。
Range1使用selectNodeContents()进行选择,顾名思义其startContainer/endContainer/commonAncerstorContainer都是传入节点<p>。startOffset是0,endOffset显然是p的子元素长度,此处为2。
《JavaScript高级程序设计》Chapter 12 DOM2和DOM3
标签:2.4 scrollto 高级 移动 container toe height ctc case
原文地址:http://www.cnblogs.com/ideal-idiot/p/7779085.html