[js] DOM操作
来源:互联网 发布:网管监控软件 编辑:程序博客网 时间:2024/06/15 06:02
DOM
operation
e.appendChild(newNode) // append newNode at the last of e's child list, return it. if newNode is already one node in html, it would moved here e.insertBefore(newNode, positionedNode) // append newNode to position, null to last onee.replaceChild(newNode, toBeReplacedNode)e.removeChild(toBeRemovedNode)e.cloneNode(boolean) // true to deep-clone, false to shallow-copy
create
document.createElement() // create new ele, not in flow now, must be append or writedocument.createTextNode()document.write(node) // write new node to flow // use this after onload would cover former document
change content
e.innerHTML = new HTMLe.attribute = new attre.style.property=new style
text
have no child
e.nodeName = '#text'e.nodeValue // value, can be modified, and will auto transcodee.normalize() // merge all text nodee.splitText(position) // split text at position
query
e.childNodes // array, all childe.firstChild // first child nodee.firstElementChild // first ele child node e.lastChilde.lastElementChilde.parentNodee.offsetParent // the nearest positioned parent elee.previousSibling // the previous one nodee.previousElementSibling // the previous ele nodee.nextSibling e.nextElementSibling
ele function
e.tagName or e.nodeNamee.getAttribute(attr) e.setAttribute(attr, value) e.removeAttribute(attr)
tips
在IE8以上获取子节点
var arr = Array.prototype.slice.call(node.childNodes, 0);
lookme
1. display none & visibility hidden
first will remove from struction, no width and height, visibility only hide it. So display will cause reflow and both will cause redraw
2. window.onload & $(document).ready
ready occurs after the document has been loaded, onload occurs later, when all content(e.g. img) has been loaded.
3. html=document.documentElement
4. 动态script
document.writevar s = document.createElement("script"); s.type = "text/javascript"; s.src = "test.js"; document.body.appendChild(s);
5.动态css
**6.**DOM是动态查询的,所以最好减少使用
0 0
- js 中的dom操作
- js操作dom
- js 操作dom
- js 对 dom 操作
- Js操作DOM
- js操作dom节点
- js操作dom
- js 操作dom
- js dom操作API
- js操作xml dom
- js的DOM操作
- JS常用dom操作
- js操作dom对象
- JS DOM操作
- js操作DOM节点
- JS操作DOM
- js常用DOM操作
- js DOM模型操作
- CentOS6.4下Mysql数据库的安装与配置
- scanf()函数中%[]格式控制符用法
- 第一个工作项目(2)- 忆往昔
- java设置一段代码执行超时时间
- Linux、GUN/Linux、GUN、GPL以及各个发行版本详细介绍
- [js] DOM操作
- 使用git commit命令时遇到 fatal: Unable to create index.lock File exists 错误的解决办法
- 获取当前屏幕的密度只
- 简洁天气源码(经测可使用)
- Android 5.x Theme 与 ToolBar 实战
- 通向架构师的道路(第八天)之weblogic与apache的整合与调优
- 创建数据库表空间、表及用户
- VC+ADO+多线程高效、安全的读写数据库
- Ubuntu下安装memcache,以及python-memcach