Fork me on GitHub

17.获取DOM节点

window 代表浏览器窗口
//alert 弹窗
window.alert('你好')
//获取浏览器窗口大小
window.innerHeight
678
window.innerWidth
668
window.outerHeight
752
window.outerWidth
1280

navigator 封装了浏览器的信息,大多数时候不会用这个对象,容易被人为修改
screen 代表屏幕
获取屏幕的宽度和高度
screen.height
800
screen.width
1280

-----------------------------------------------------------------------------

location:代表当前网站页面的URL信息
location.reload() 刷新页面
location.assign('目标网址') 设置新的地址
document:代表当前的页面文档信息
//修改当前页面的标题
document.title='博客园'

获取具体的文档树节点
document.getElementById('具体ID')
document.getElementsByTagName('具体标签');
document.getElementsByClassName('具体class名字');
父类名字.children 获取所有子类的节点

获取cookie
document.cookie 获得当前页面的cookie

history (不建议使用)
//前进
history.forward()
//后退
history.forward()

posted @   一名狗书匠&  阅读(4)  评论(1编辑  收藏  举报
相关博文:
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· 三行代码完成国际化适配,妙~啊~
· .NET Core 中如何实现缓存的预热?

asd

点击右上角即可分享
微信分享提示