js09 bom+dom
BOM---->browser Object model浏览器对象模型
1)BOM操作浏览器的:前进,后台,刷新,打印,关闭,打开新的小窗口
2)BOM对象的顶级对象是 window
BOM是没有规范的,DOM有规范,遵循w3c的规范
location属性:
console. log (location.href) ;
console.1og(location. protocol);
console. log(location. host);
console. log(location. hostname);
console. log( location. pathname );
console. log( location. search);
console. log(location. hash);
location方法:
//方法 //跳转1会产生 前进与后台.
// location. assign("http:/ /www . baidu. com" )
//跳转2替换,不会产生前进与后台
// location . replace("http:qq. com")
//跳转3 // location. href
//跳转4 // location= "http: / /baidu. com"
//刷新 // location. reload()
history历史记录
// history // history. forward()//前进
// history.back()后台
// history.go() //1前进 //0刷新 // -1后退
//history.length当前有多少条历史记录
//1).根据id获取页面上的元素
oBtn=document.getElementById("btn")
oBtn.style.backgroundColor="green"
//2).根据类名称获取页面上的元素
oBtns=document.getElementsByClassName("cls")
console.log(oBtns)
oBtns[0].style.backgroundColor="red"
oBtns[1].style.backgroundColor="yellow"
//3).根据name获取页面上元素
oNames=document.getElementsByName("mybtn")
console.log(oNames) oNames[0].style.backgroundColor="blue"
oNames[1].style.backgroundColor="skyblue"
//4).根据标签名称获取元素
var tagNames=document.getElementsByTagName("button")
for(var i=0;i<tagNames.length;i++){ tagNames[i].style.backgroundColor="red" }

浙公网安备 33010602011771号