JavaScript 基础05-JS DOM
DOM
1. DOM基本介绍
DOM 是 Document Object Model 文档对象模型
- HTML DOM
- XML DOM
2. HTML DOM 对象参考
2.1 document 对象
- 属性:
- domain
- lastModified
- referrer
- URL
- cookie
- 集合属性all 获取所有元素(IE中为true,非IE为false)
- 方法:
- 属性:
2.2 form 对象
属性:1
2-length 元素个数
-elements 元素数组方法:
- submit() 提交指定的表单 - reset() 重置指定的表单事件:
-onsubmit="return false" 阻止提交表单,submit()方法可绕过 -onreset="return false" 阻止重置表单,reset()方法可绕过2.3 image 对象
2.4 anchor 对象
2.5 base 对象
2.6 canvas 对象
http://echarts.baidu.com/2.7 Event 对象
2.8 input 系列对象
- blur()
- focus()
- select()
复制 flash或clipboard.js组件
2.9 select 对象
2.10 option 对象
2.11 style 对象
2.12 table 对象
2.13 tableRow 对象
2.14 tableCell 对象
3.XML DOM 节点
1.节点介绍
- 1.1 什么是节点 node
HTML 文档中 所有的组成部分 称之为节点
doucment 文档
element 标签
attr 属性 (attribute)
comment 注释
text 文本
1.2 节点树
子节点
父节点
同辈节点
后代节点
先辈节点1.3 节点的访问
- 得到节点
- doucment 文档
document - element 标签
ByID… - attr 属性 (attribute)
getAttributeNode(attrname) - comment 注释
子节点 - text 文本
子节点
- doucment 文档
- 获取子节点
childNodes - 获取子元素节点
children - 获取第一个子节点
firstChild - 获取最后一个子节点
lastChild - 获取父节点
parentNode - 获取父元素节点
parentElement - 获取前一个节点
previousSibling - 获取后一个节点
nextSibling
- 得到节点
1.4 节点属性
- nodeName
- doucment #document
- element 标签名
- attr 属性名
- text #text
- comment #comment
- nodeValue
- doucment null
- element null
- attr 属性值
- text 文本内容
- comment 注释内容
- nodeType
- doucment 9
- element 1
- attr 2
- text 3
- comment 8
- nodeName
2.节点操作
2.1 获取节点
- element ById/子节点/父节点/同辈节点/后代
- attr getAttributeNode(‘attrname’); 获取属性节点
element.attr; 获取属性值 getAttribute('attrname'); 获取属性值
2.2 改变节点(改变节点的值) nodeValue
- element 无意义
- attr
setAttribute('attrname', 'value'); element.attr = value;
2.3 删除节点
- attr removeAttribute(‘attrname’);
- element 把值赋值为空 或 removeChild(node) 需要找到父节点
2.4 替换节点
- attr setAttribute(‘attrname’, ‘value’);
- element replaceChild(new_node, old_node) 需要找到父节点
2.5 插入节点
- attr
setAttribute('attrname', 'value'); setAttributeNode('attrname'); - element
appendChild(node) 追加 insertBefore(new_node, old_node) 指定位置
2.6 创建节点
- attr document.createAttribute(attrname);
- element document.createElement(‘tagName’);
2.7 克隆节点
- cloneNode() 参数默认为false / 可选 true
3. XML 对象
- node
- nodeList
- document
- element
- attr
- text
- comment
4. HTMLElement对象
1 | className 类名 |
PS. 补充
- PS1. DOM 元素对象的 属性和方法
http://www.runoob.com/jsref/dom-obj-all.html - PS2. MDN文档
- Mozilla 开发者社区(MDN):
https://developer.mozilla.org/zh-CN/ - JavaScript MDN文档
https://developer.mozilla.org/zh-CN/docs/Web/JavaScript
- Mozilla 开发者社区(MDN):
特效-全选复制按钮
1 | <h1>input</h1> |
特效-瀑布流效果
1 | <h1>瀑布流效果</h1> |