基础JS

JS常用API手册5-dom

2017-11-24  本文已影响20人  桃花島主
"http://image.baidu.com/channel?c=宠物#宠物"
hash    1.#最后的内容        eg:"#宠物"
host    2.主机名           eg:"image.baidu.com"
hostName   3.主机名            eg:"image.baidu.com"
port       4.端口         eg:""
pathName   5.除去host之外的名字        eg:"/channel"
protocol    "http:"
search     eg:"?c=宠物"
href       eg:"http://image.baidu.com/channel?c=宠物#宠物"

常用:

window.location.href="your url";    //有历史记录
window.location.reload(true);//强制刷新
window.location.reload();//缓存刷新
window.location.replace("you url");     //没有历史记录

frame

浏览器检测

主要以下2种:

DOM

document.documentElement //就是html标签

table

table.caption   //获取caption节点[唯一]
table.tHead     //获取head节点[唯一]
table.tFoot     //获取foot节点[唯一]
table.tBodies       //获取全部的body

//行和单元格的操作
table.rows  //返回所有的行
table.rows[rowIndex].cells  //返回所有的行
oneRow.rowIndex //获取下标
oneRow.sectionRowIndex  //当前tbody中的下标,不是全局的
oneCell.cellIndex   //获取单元下标
//表头的操作
table.createCaption();  //没有的创建新表头,有的返回已有的表头
table.createTHead();
table.createTFoot();

table.deleteCaption();
table.deleteTHead();
table.deleteTFoot();

table.insertRow(rowIndex);
row.insertCell(cellIndex);

table.deleteRow(rowIndex);
row.deleteCell(cellIndex);

document属性

属性 描述
cookie 设置或返回与当前文档有关的所有 cookie
domain 返回当前文档的域名
lastModified 返回文档被最后修改的日期和时间
referrer 返回载入当前文档的文档的 URL
title 返回当前文档的标题
URL 返回当前文档的 URL

nodelist

元素节点属性

element.attributes[attName].nodeValue
element.attributes[attName].nodeValue = '自定义数值'

节点类型

节点类型 数值常量 字符常量
Element(元素节点) 1 ELEMENT_NODE
Attr(属性节点) 2 ATTRIBUTE_NODE
Text(文本节点) 3 TEXT_NODE
Comment(注释节点) 8 COMMENT_NODE

属性判定

属性-CSS类

属性-HTML代码/文本/值

创建元素节点

选择器-基本

document.forms[0]       取得第一个表单元素的内容
document.froms[formName]
document.froms[formName].elements[表单中所有元素的集合][推荐的使用方法]
document.froms[formName].elements[0]
document.froms[formName].elements[elementName]      名字相同的控件radio会返回一个NodeList

文档处理-内部插入

//向元素添加新的子节点,作为最后一个子节点[返回新增的子节点(如果该节点在文档中已经存在,就把改节点移动到现在的位置)]。
element.appendChild(newNode)

文档处理-外部插入

//在指定的已有的子节点之前插入新节点。
element.insertBefore(newNode, refNode)

文档处理-替换

//替换元素中的子节点。
element.replaceChild(newChild, oldChild)        

文档处理-删除

//从元素中移除子节点[返回被删除的节点oldNode]。
element.removeChild(oldNode)

文档处理-复制

//克隆元素[是否进行深复制(这个节点就是个孤儿节点)]。
element.cloneNode(booleanFlag)

insertAdjacentHTML方法

筛选-过滤

//如果元素拥有指定属性,则返回true,否则返回 false。
element.hasAttribute()  
//如果元素拥有属性,则返回 true,否则返回 false。
element.hasAttributes() 
//如果元素拥有子节点,则返回 true,否则 false。
element.hasChildNodes() 

筛选-查找

上一篇 下一篇

猜你喜欢

热点阅读