02-09
2-9
1、列举所有获取 DOM 元素的方法
通过ID获取(getElementById)
通过name属性(getElementsByName)
通过标签名(getElementsByTagName)
通过类名(getElementsByClassName)
通过选择器获取一个元素(querySelector)
通过选择器获取一组元素(querySelectorAll)
获取html的方法(document.documentElement)
document.documentElement是专门获取html这个标签的
获取body的方法(document.body)
document.body是专门获取body这个标签的
2、列举添加 DOM 元素的方法
document.getElementById('元素的ID')
document.getElementsByTagName('元素的标签名')
document.documentElement 获取HTML元素
document.querySelector() 获取一个
document.querySelectorAll() 获取多个
3、列举移除 DOM 元素的方法
remove()
4、分别列举 BOM 常用对象 location navigator history screen 中的属性和方法
1. location.href = "http://www.jd.com"; //属性
location.assign("http://www.jd.com"); //方法
//重新加载
location.reload();
//以地址替换的形式,进行页面的转换
location.replace("http://www.jd.com"); //不存历史记录
//location的属性和方法
console.log(window.location);
// 打印地址栏上#及后面的内容
console.log(location.hash);
//主机和端口号
console.log(location.host);
console.log(location.hostname);
//文件的路径---相对路径
console.log(location.pathname);
//端口号
console.log(location.port);
//协议
console.log(location.protocol);
//搜索内容
console.log(location.search)
2. 通过platform可以判断浏览器所在的系统平台的类型
console.log(window.navigator.platform);
console.log(window.navigator.userAgent);
3. window.history.go(1);//前进
window.history.back();//后退
4. availHeight 返回屏幕的高度(不包括Windows任务栏)
availWidth 返回屏幕的宽度(不包括Windows任务栏)
colorDepth 返回目标设备或缓冲器上的调色板的比特深度
height 返回屏幕的总高度
pixelDepth 返回屏幕的颜色分辨率(每象素的位数)
width 返回屏幕的总宽度