前端面试——JS Web API

DOM与BOM

DOM的本质
DOM是一种树形结构的数据结构

DOM节点操作

const div1 = document.getElementById('div1')
console.log('div1', div1)

const divList = document.getElementsByTagName('div') // 集合
console.log('divList.length', divList.length)
console.log('divList[1]', divList[1])

const containerList = document.getElementsByClassName('container') // 集合
console.log('containerList.length', containerList.length)
console.log('containerList[1]', containerList[1])

const pList = document.querySelectorAll('p')
console.log('pList', pList)

const pList = document.querySelectorAll('p')
const p1 = pList[0]

attribute和property
property只是一个JS对象的属性的修改,不会体现到html结构当中。(通过obox.name = xxx操作) attribute是对html便签属性的修改。
BOM

navigator.userAgent//浏览器类型
location.href
location.protocol  
location.pathname  
location.search  
location.hash

你可能感兴趣的:(前端面试——JS Web API)