Dom元素及其操作

本文详细介绍了DOM中的document对象和Element的使用,包括查询、创建、插入、删除元素的方法,如querySelector、createElement,以及属性操作、样式修改、class操作、页面宽高计算等。还讨论了如何获取计算后的样式和批量操作CSS,以及DOM元素选取的API。
摘要由CSDN通过智能技术生成

Dom元素及其操作

  • Document Object model(文件对象模型)

document对象

html文档都会变成

  • document.head
  • document.body

readyState

返回当前文档状态

  1. loading:加载HTML代码阶段,尚未完成解析
  2. interactive:加载外部资源阶段
  3. complete:全部加载完成

documnet.location

  • // 假定当前网址为http://user:passwd@www.example.com:4097/path/a.html?x=111#part1
  • document.location.href // “http://user:passwd@www.example.com:4097/path/- - a.html?x=111#part1”
  • document.location.protocol // “http:”
  • document.location.host // “www.example.com:4097
  • document.location.hostname // “www.example.com
  • document.location.port // “4097”
  • document.location.pathname // “/path/a.html”
  • document.location.search // “?x=111”
  • document.location.hash // “#part1”
  • document.location.user // “user”
  • document.location.password // “passed”

// 跳转到另一个网址

  • document.location.assign(‘http://www.google.com’)
    // 优先从服务器重新加载
  • document.location.reload(true)
    // 优先从本地缓存重新加载(默认值)
  • document.location.reload(false)
    // 跳转到另一个网址,但当前文档不保留在history对象中,
    // 即无法用后退按钮,回到当前文档
  • document.location.assign(‘http://www.google.com’)
    // 将location对象转为字符串,等价于document.location.href
  • document.location.toString()documnet.location.href 获取地址的缓存

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值