让前端飞

慕课网《前端JavaScript面试技巧》学习笔记(6)-DOM

2017-07-14  本文已影响0人  Yangkeloff

1.DOM是哪种基本的数据结构
2.DOM操作常用的API有哪些
3.DOM节点的attr和property有何区别
4.如何检测浏览器的类型
5.拆解url的各部分

知识点#####

标签属性,用于扩充HTML标签,可以改变标签行为或提供数据,格式为name=value
var pList=document.querySelectorAll('p') var p=pList[0] p.getAttribute('data-name') p.setAttribute('data-name','imooc') p.getAttribute('style') p.setAttribute('style','font-size:30px;')

var div1=document.getElementById('div1')
var p1=document.createElement('p') //创建新节点
p1.innerHTML='Hello'
div1.appendChild(p1)  //添加新创建的节点
var p2=document.getElementById('p2')
div1.appendChild(p2)  //移动已有节点
var div1=document.getElementById('div1')
var parent=div1.parentElement //获取父元素
var child=div1.childNodes //获取子元素
div1.removeChild(child[0])  //移除child[0]子节点
//ua
var ua=navigator.userAgent
var isChrome=ua.indexOf('Chrome')
console.log(isChrome);
 
  //screen
console.log(screen.width);
console.log(screen.height);
//location
console.log(location.href);
console.log(location.protocol); //http https
console.log(location.pathname); //域名之后的路径
console.log(location.search);
console.log(location.hash);

  //history
history.back()
history.forward()
解题#####

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

2.DOM操作常用的API有哪些

3.DOM节点的attr和property有何区别

4.如何检测浏览器的类型

navigator.userAgent

5.拆解url的各部分

//location
console.log(location.href);
console.log(location.protocol); //协议 http https
console.log(location.pathname); //域名之后的路径
console.log(location.search);
console.log(location.hash);
上一篇下一篇

猜你喜欢

热点阅读