BOM与DOM操作
BOM
- BOM是浏览器对象模型
- BOM操作
window.open()
window.close()
window.navigator.userAgent()
window.history.forward()
window.history.back()
window.location.href
window.location.href = 新网址
window.location.reload()
alter()
confirm()
prompt()
定时器的相关操作*
function func1(){
alert('终于要干饭了')
}
let t = setTimeout(func1,3000)
clearTimeout(t)
var s1 = null
function showMsg() {
function func1(){
alert('终于要干饭了')
}
s1 = setInterval(func1, 3000)
}
function clearMission(){
clearInterval(s1)
}
setTimeout(clearMission, 9000)
showMsg()
DOM
document.getElementById()
document.getElementsByClassName()
document.getElementsByTagName()
parentElement 父节点标签元素
children 所有子标签
firstElementChild 第一个子标签元素
lastElementChild 最后一个子标签元素
nextElementSibling 下一个兄弟标签元素
previousElementSibling 上一个兄弟标签元素
节点操作:
let XEle = document.createElement('标签名')
XEle.href = 'url'
XEle.id = 'id值'
XEle.innerText = '内部文本'
divEle.append(XEle)
属性操作:
XEle.属性
XEle.setAttribute()
文本操作:
divEle.innerHTML
divEle.innerText
实操:
divEle.innerHTML = '<h1>嘿嘿嘿</h1>'
'<h1>嘿嘿嘿</h1>'
divEle.innerText = '<h1>哈哈哈</h1>'
'<h1>哈哈哈</h1>'