什么是 DOM、BOM?
DOM:
文档对象模型,即:document 。
BOM:
浏览器对象模型,即:window 。
它既是操作浏览器窗口的接口,又是一个全局对象。document也是window下的一个子对象
说几个很实用的BOM属性对象方法?
location对象
location.href一返回或设置当前文档的URL location.search 一返回URL中的查询字符串部分。
例如:
location.href一返回或设置当前文档的URLlocation.search 一返回URL中的查询字符串部分。例如:http://www.dreamdu.com/dreamdu.php?id=5&name=dreamdu 返回?id=5&name=dreamdulocation.hash 一返回URL#后面的内容,如果没有#,返回空location.host 一返回URL 中的域名部分,例如 www.dreamdu.comlocation.hostname 一返回URL中的主域名部分,例如dreamdu.comlocation.pathname 一返回URL的域名后的部分,例如http://www.dreamdu.com/xhtml/ 返回/xhtml/location.port --返回URL 中的端口部分。例如httD://www.dreamdu.com:8080/xhtml/ 返回8080location.protocol --返回URL 中的协议部分。例如httD://www.dreamdu.com:8080/xhtail/ 返回(//)前面的内容http:location.assign 一设置当前文档的URLlocation.replace() 一设置当前文档的URL,并且在history对象的地址列表中移除这个 URLlocation.replace(url); location.reload()--重载当前页面
history 对象
history.go() --前进或后退指定的页面数history.go(num);history.back() --后退一页history.forward() --前进一页
Navigator对象
navigator.userAgent -返回用户代理头的字符串表示(就是包括浏览器版本信息等的字符串)navigator.cookieEnabled --返回浏览器是否支持(启用)cookie
DOM的增删改查
创建新节点
createDocumentFragment() // 创建一个DOM片段createElement() // 创建一个具体的元素createTextNode() // 创建一个文本节点
添加、移除、替换、插入
appendChild(node)removeChild(node)replaceChild(new,old)insertBefore(new,old)
查找
getElementById();getElementsByName();getElementsByTagName();getElementsByClassName();querySelector();querySelectorAll();
属性操作
getAttribute(key);setAttribute(key, value);hasAttribute(key);removeAttribute(key);
