DOM和BOM

注:W3C标准没有规定任何JS基础相关的东西(如:变量类型、原型、作用域、异步)。它只管定义用于浏览器中JS操作页面的API和全局变量。

JS内置的全局函数和对象:object、Array、Boolean、string、Math、JSON、window、document、Navigator、UserAgent

1、DOM的本质——文档对象模型

     DOM可以理解为:浏览器把拿到的html代码,结构化一个浏览器能识别并且JS可操作的一个模型而已。

2、DOM节点操作:获取DOM节点、prototype、Attribute

(1)获取DOM节点

         document.getElementById(“”);    //元素

         document.getElementsByTagName(“”);  //集合

         document.getElementsByClassName(“”);  //集合

         document.querySelectorAll(“”);  //集合

(3)property

(4)Attribute

    var pList = document.querySelectorAll('p');

    var p = pList[0];

    p.getAttribute('data-name');

    p.getAttribute('data-name','imooc');

    p.getAttribute('style');

    p.setAttribute('style','font-size:30px;')

3、DOM结构操作

(1)添加新节点

    var div1 = document.getElementById("");

    var p1 = document.createElement('p');

    p1.innerHTML = "this is p1";

    div1.appendChild(p1);   //添加新创建的元素

    var p2 = document.getElementById('')

    div1.appendChild(p2)

(2)获取父元素和子元素

    var div2 = document.getElementById('');

    var parent = div2.parentElement;   //父元素

    var child = div2.childNodes;    //子元素,集合

(3)移除元素

div2.removeChild(child[0]);

解答:

1、DOM是哪种基本的数据结构?   

2、DOM操作的常用API有哪些?

    获取DOM节点,以及节点的property和Attribute

   获取父节点,获取子节点;新增节点;删除节点

3、DOM节点的Attribute和property有何区别?

     property:只是一个JS对象的属性的修改

     Attribute:是对HTML标签属性的修改

 

BOM操作——浏览器对象模型

知识点:navigator、screen、location、history

1、如何检测浏览器类型?navigator & screen

    var ua = navigator.userAgent;

    var isChrome = ua.indexOf('Chrome');

    console.log(isChrome);   //true   false

    screen.width;

    screen.height;

2、location和history

拆解url各部分:

location.href  http://coding.m.imooc.com/classindex.html?Cid=99&a=b#mid=100

location.protocol     //http’’https

location.host         //主机名  coding.m.imooc.com

location.pathname     //.../.../    /classindex.html

location.search    //参数    ?Cid=99&a=b

location.hash      //哈希    #mid=100

history.back()

history.forward()

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值