读JS高级API笔记_(DOM&&DOM2&&DOM3)哎呀——园龄才9个月啊
---恢复内容开始---
运行下面代码
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>DOM2 && DOM3 || HTML5DOMAPI</title> </head> <body> <div> <p>12312</p> <ul> <li>1</li> <li>11</li> <li>111</li> <li>1111</li> </ul> </div> <script> root = document.querySelector('div'); //带命名空间的文档结构 /* <xhtml:body xhtml:class="xx"> </xhtml:body> */ root.localName //不带XML空间前缀的tagName document.doctype.publicId //"-//W3C//DTD XHTML 1.0 Transitional//EN" document.doctype.systemId //"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" document.importNode; //解决不同DOM类型之间的DOM&node移动操作 document.defaultView //window 当前的window环境 //document.contentDocument /*for标准*/|| document.contentWindow.document /*for IE*/ document.styleSheets document.scripts /* style */ style = { cssText : '', //样式 length : '', //有几个样式 getPropertCssValue : '', getPropertyValue : '', "item(index)" : '', //返回第索引个的样式 removeProperty : '', setProperty : '' }; //HTML5元素遍历 //NodeIterator ,treeWalker var iterator = document.createTreeWalker(root,NodeFilter.SHOW_ELEMENT,filter,false); function filter( node ){ //有点想 ARRAY.prototype.sort方法 return node.tagName.toLowerCase() === 'li' ? NodeFilter.FILTER_ACCEPT : //接受这个节点 NodeFilter.FILTER_SKIP //过滤掉这个节点 }; node = iterator.nextNode(); //专有方法 nextNode() 和previousNode() ,取得节点的元素 while( node != null){ console.log(node.tagName); node = iterator.nextNode(); }; //获取range方法, var range = document.createRange(); range.selectNode(root); console.log( range ); //range.setStart(obj,offset) //range.setEnd(obj,offset) //range.extraContent; //range.cloneContent; //range.insertNode; //range.surrandContent(span); //range.collapse( true or false ); //range.compareBoundaryPoints(0 || 1 || 2 || 3,range2); root.classList; root.classList.contain; root.classList.add; root.classList.remove; root.classList.toggle; document.activeElement; //默认body /* data-xx ; dataSet.xx = 1; 存数据的,实现更快访问 */; //[ //beforebegin, //afterbegin, //beforeend, //afterend //] root.insertAdjacentElement root.insertAdjacentText root.insertAdjacentHTML root.insertAdjacentBefore //HTML5 scrollAPI document.body.scrollIntoView() document.domain //可以实现同一个域名不同二级域名的跨域,但是只能document.domain更改一次,否则会报错 root.nodeType === '3' ? root.normalize()&&root.splitText('aaa/*这个是切割标志符*/') : '' document.createComment('\'xxx'); var aDiv = document.getElementsByTagName('div'); //这个aDiv是根据页面自动更新的 </script> </body> </html>
//娃哈哈,博客园的恢复功能不错
---恢复内容结束---
天道酬勤
本文作者:方方和圆圆
本文链接:https://www.cnblogs.com/diligenceday/p/3485685.html
版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步