Document.title 设置文档标题等价于<title>标签。
Document.bgcolor 背景颜色
Document.fgcolor 前景颜色(文本颜色)
Document.linkcolor 未点击的连接颜色 Document.alinkcolor 焦点在连接上的颜色
Document.vlinkcolor点击过后的连接颜色
Document.charset 字符集
Document.cookie 设置和读取cookie
常用方法
Document.write();
Document.createElement(Tag); //创建一个html标签对象.
Document.getElementById(id) //获取指定ID值的对象。
Document.getElementsByName(name) //获取指定Name值的对象。
Document.body //<body ></body>
Document.body.link
Document.body.alink
Document.body.vlink
Document.body.text
Document.body.leftMargin
Document.body.rightMargin
Document.body.topMargin
Document.body.bottomMargin
Document.body.background
Document.body.innerText //在<body>文本内容</body>
Document.body.innerHTML //在<body>HTML代码</body>
Document.body.appendChild(Tag);//绑定一个对象到正文部分
常用事件
Document.body.onclick = “”
Document.body.onmouseover = “”
Document.body.onmouseout = “”
=================
HTML DOM
DOM (Document Object model)文档对象模型
DOM树结构:
Document – 最顶层的节点,其他节点都附属于它。
DocumentType - DTD引用节点
DocumentFragment – 碎片文档
Element – 表示起始标签到结束标签之间的内容
Attr – 表示属性名和内容
Text 表示标签之间的文本内容
CDataSection – 节点
Entity – Entity定义节点
EntityReference – 实体引用节点
ProcessingInstruction – PI节点
Comment 注释节点
Notation – DTD规范中定义的记号
创建节点的方法
createElement(tagname) 创建一个标签名为tagname的元素
createTextNode(text) 创建一个包含文本text的文本节点
appendChild(节点对象) 添加节点
removeChild(节点对象) 删除节点对象
删除当前节点的子节点,返回删除的节点。这个被删除的节点可以被插入到其他地方。
节点的parentNode特性
replaceChild(节点1,节点2)用节点1替换节点2。
insertBefore(节点1,节点2)在节点2之前插入节点1.
cloneNode(deepBoolean)复制节点,复制了原节点的属性,在把这个新节点插入到document前需要修改ID属性确保ID值唯一。
布尔参数 deepBoolean 为true时,复制当前节点的所有子节点,包括该节点内的文本。
Node接口 attributes方法
注意,只有element节点才能具有该特性。
getNamedItem(name) 返回nodename属性值等于name的节点
setNamedItem(node)
NameNodeMap对象 length 包含节点数量的。
<p style=”color:red” id=”p1”>nihao</p>
Var pp = document.getElementById(“p1”);
pp.attributes.getNamedItem(“id”).nodevalue = “yy”;
pp.attributes.item(0).nodevalue
getAttribute(name)
setAttribute(name,value)
getElementsByTagName();
Javascript操作xml 例:testxml.html
XMLHttpRequest对象
创建XMLHttpRequest对象的语法:
xmlhttp = new XMLHttpRequest();
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP ");
OPEN(“GET、POST”,url,true);
Send()