什么是 DOM、BOM?

DOM:
文档对象模型,即:document 。

BOM:
浏览器对象模型,即:window 。
它既是操作浏览器窗口的接口,又是一个全局对象。document也是window下的一个子对象

说几个很实用的BOM属性对象方法?

location对象

location.href一返回或设置当前文档的URL location.search 一返回URL中的查询字符串部分。
例如:

  1. location.href一返回或设置当前文档的URL
  2. location.search 一返回URL中的查询字符串部分。
  3. 例如:http//www.dreamdu.com/dreamdu.php?id=5&name=dreamdu 返回?id=5&name=dreamdu
  4. location.hash 一返回URL#后面的内容,如果没有#,返回空
  5. location.host 一返回URL 中的域名部分,例如 www.dreamdu.com
  6. location.hostname 一返回URL中的主域名部分,例如dreamdu.com
  7. location.pathname 一返回URL的域名后的部分,例如http://www.dreamdu.com/xhtml/ 返回/xhtml/
  8. location.port --返回URL 中的端口部分。例如httD//www.dreamdu.com:8080/xhtml/ 返回8080
  9. location.protocol --返回URL 中的协议部分。
  10. 例如httD//www.dreamdu.com:8080/xhtail/ 返回(//)前面的内容http:
  11. location.assign 一设置当前文档的URL
  12. location.replace() 一设置当前文档的URL,并且在history对象的地址列表中移除这个 URL
  13. location.replace(url); location.reload()--重载当前页面

history 对象

  1. history.go() --前进或后退指定的页面数history.go(num);
  2. history.back() --后退一页
  3. history.forward() --前进一页

Navigator对象

  1. navigator.userAgent -返回用户代理头的字符串表示(就是包括浏览器版本信息等的字符串)
  2. navigator.cookieEnabled --返回浏览器是否支持(启用)cookie

DOM的增删改查

  1. 创建新节点

    1. createDocumentFragment() // 创建一个DOM片段
    2. createElement() // 创建一个具体的元素
    3. createTextNode() // 创建一个文本节点
  2. 添加、移除、替换、插入

    1. appendChild(node)
    2. removeChild(node)
    3. replaceChild(new,old)
    4. insertBefore(new,old)
  3. 查找

    1. getElementById();
    2. getElementsByName();
    3. getElementsByTagName();
    4. getElementsByClassName();
    5. querySelector();
    6. querySelectorAll();
  4. 属性操作

    1. getAttribute(key);
    2. setAttribute(key, value);
    3. hasAttribute(key);
    4. removeAttribute(key);