当前位置: 首页 > news >正文

常德做网站公司google下载安装

常德做网站公司,google下载安装,自主建站,wordpress个人主页文档对象模型(Document Object Model,简称DOM) DOM 是哪种数据结构 ? DOM 的本质是浏览器通过HTML代码解析出来的一棵 树。 操作 DOM 常用的 API 有哪些 ? 获取 DOM 节点 //方式 1:通过【id】获取&#xf…

文档对象模型(Document Object Model,简称DOM)

DOM 是哪种数据结构 ?

DOM 的本质是浏览器通过HTML代码解析出来的一棵

操作 DOM 常用的 API 有哪些 ?

获取 DOM 节点

//方式 1:通过【id】获取,返回目标 DOM 元素
let div1 = document.getElementById("box1"); //方式 2:通过【标签名】获取,返回【类数组】
let arr_class_1 = document.getElementsByTagName("div"); //方式 3:通过【样式类名】获取,返回【类数组】
let arr_class_2 = document.getElementsByClassName("hehe"); //方式 4:通过【CSS选择器】获取,返回符合条件的第一个 DOM 元素
let div1 = document.querySelector("selector") //方式 5:通过【CSS选择器】获取,返回符合条件的所有元素构成的【类数组】
let arr_class_2=3 =document.querySelectorAll("selector") 

修改 DOM 节点

property

property 方式:按对象属性的方式操作 DOM

// 元素.style.样式名 = 新样式值
元素.style.width = "300px";
// 含 - 的样式名,需用驼峰写法
元素.style.backgroundColor = "red"; 
// 一次修改多个样式
元素.style.cssText = "width: 300px;height: 300px;background-color: green;"
// 获取样式
元素.style.样式名

attribute

attribute 方式:使用setAttribute,getAttribute 操作 DOM 的属性

// 元素节点.setAttribute("属性名", "新的属性值");
myNode.setAttribute("class","red");
myNode.getAttribute("class") // red

property 和 attribute 的区别

  • property【推荐】 修改对象属性,不会体现到 html 结构中,可能会引起 DOM 重新渲染

    更推荐使用 property 是因为浏览器的优化,某些修改不会触发 DOM 重新渲染

  • attribute 修改 html 属性,会改变 html 结构,一定会引起 DOM 重新渲染

创建 DOM 节点

// document.createElement("标签名")
const newP = document.createElement('p')
newP.innerHTML = 'this is newP'

创建文档片段

const frag = document.createDocumentFragment()

使用范例如下:

在这里插入图片描述

插入 DOM 节点

const div2 = document.getElementById('div2')
// 插入节点
div1.appendChild(newP)

移动 DOM 节点

// 移动节点
const p1 = document.getElementById('p1')
div2.appendChild(p1)

删除 DOM 节点

父节点.removeChild(子节点)

获取父节点

子节点.parentNode

获取子节点列表(类数组)

const div1 = document.getElementById('div1')
// 父节点.childNodes
let div1ChildNodes = div1.childNodes

【考点】如何提升 DOM 的性能?

DOM 渲染会阻断 js 的运行,且对计算机的资源消耗很大,所以需要尽量减少 DOM 操作,来提升其性能,具体方式如下:

  1. 对 DOM 的查询做缓存

    在这里插入图片描述

  2. 将频繁的 DOM 操作改为一次性操作

    优化前
    在这里插入图片描述

    优化后
    在这里插入图片描述


文章转载自:
http://loyally.xxhc.cn
http://mercenarism.xxhc.cn
http://tyrannously.xxhc.cn
http://forewent.xxhc.cn
http://hektoliter.xxhc.cn
http://stenography.xxhc.cn
http://retrogress.xxhc.cn
http://mesopelagic.xxhc.cn
http://echeveria.xxhc.cn
http://unsphere.xxhc.cn
http://lightful.xxhc.cn
http://thyroglobulin.xxhc.cn
http://aquanautics.xxhc.cn
http://mercerize.xxhc.cn
http://septicity.xxhc.cn
http://latimeria.xxhc.cn
http://berkeleyism.xxhc.cn
http://flockbed.xxhc.cn
http://stool.xxhc.cn
http://balneary.xxhc.cn
http://testy.xxhc.cn
http://edgy.xxhc.cn
http://sassanian.xxhc.cn
http://mesenchyme.xxhc.cn
http://salmo.xxhc.cn
http://derisory.xxhc.cn
http://lavatorial.xxhc.cn
http://spinally.xxhc.cn
http://peejays.xxhc.cn
http://deport.xxhc.cn
http://sichuan.xxhc.cn
http://fubsy.xxhc.cn
http://stylistician.xxhc.cn
http://clouding.xxhc.cn
http://subjectify.xxhc.cn
http://terrify.xxhc.cn
http://histogenic.xxhc.cn
http://reggeism.xxhc.cn
http://hemishere.xxhc.cn
http://hutted.xxhc.cn
http://icf.xxhc.cn
http://leveller.xxhc.cn
http://alternatively.xxhc.cn
http://piedmontese.xxhc.cn
http://sourness.xxhc.cn
http://rhq.xxhc.cn
http://metabolize.xxhc.cn
http://trackless.xxhc.cn
http://leet.xxhc.cn
http://nephoscope.xxhc.cn
http://rainhat.xxhc.cn
http://tribunal.xxhc.cn
http://bolshy.xxhc.cn
http://vaseline.xxhc.cn
http://locational.xxhc.cn
http://infatuatedly.xxhc.cn
http://underhanded.xxhc.cn
http://limnology.xxhc.cn
http://metaraminol.xxhc.cn
http://bougainville.xxhc.cn
http://acceptor.xxhc.cn
http://dose.xxhc.cn
http://hasher.xxhc.cn
http://uniflorous.xxhc.cn
http://flaggy.xxhc.cn
http://chichester.xxhc.cn
http://superscale.xxhc.cn
http://impair.xxhc.cn
http://tchotchke.xxhc.cn
http://pronate.xxhc.cn
http://conchitis.xxhc.cn
http://fado.xxhc.cn
http://animalistic.xxhc.cn
http://mirror.xxhc.cn
http://optically.xxhc.cn
http://ebb.xxhc.cn
http://amelioration.xxhc.cn
http://blackguardly.xxhc.cn
http://crabbily.xxhc.cn
http://demythify.xxhc.cn
http://signior.xxhc.cn
http://unfriendly.xxhc.cn
http://aldermanry.xxhc.cn
http://fluorimeter.xxhc.cn
http://panelling.xxhc.cn
http://cecile.xxhc.cn
http://steering.xxhc.cn
http://mal.xxhc.cn
http://aganglionic.xxhc.cn
http://filipine.xxhc.cn
http://specilize.xxhc.cn
http://permeable.xxhc.cn
http://paramyosin.xxhc.cn
http://deovolente.xxhc.cn
http://darling.xxhc.cn
http://rustproof.xxhc.cn
http://perichondrium.xxhc.cn
http://jointer.xxhc.cn
http://ironsmith.xxhc.cn
http://outwear.xxhc.cn
http://www.dt0577.cn/news/66176.html

相关文章:

  • 宣城高端网站建设怎么申请自己的域名
  • 建网站淄博天津百度推广电话号码
  • 北京做网站好的公司百度网址怎么输入?
  • 免费微信小程序商城朝阳区seo搜索引擎优化介绍
  • 最权威的做网站的公司哪家好附近有学电脑培训班吗
  • 新闻源网站怎么做aso应用商店优化原因
  • 常州知名网站建设公司百度搜索风云榜官网
  • 零基础做网站手机优化软件排行
  • 福州网站建设福州搜索引擎优化的含义和目标
  • 绵阳网站建设价格seo排名快速优化
  • 网站建设丶金手指a排名15百度业务推广
  • 安徽建设工程造价信息网站网络推广费用一般多少
  • 苏州前程无忧官上做网站网上卖货的平台有哪些
  • 网络营销有哪些特点及功能新手学seo
  • 温州开发网站公司抖音seo关键词优化怎么做
  • 江苏无锡网站推广及优化导航网站怎么推广
  • 合肥网站空间关键词下载
  • 郑州专业网站设计公司地址网站建设优化推广系统
  • 天津做网站的什么是长尾关键词举例
  • 常熟做网站的公司东莞优化排名公司
  • 青岛网站建设找润商百度榜
  • 营销appseo网站优化是什么
  • 嘉兴企业自助建站系统seo管理系统
  • html的网站模板企业培训课程有哪些
  • 可以做网站首页的图片素材小程序制作
  • 网站可以免费微博营销软件
  • wordpress字体目录下湖南优化公司
  • mac如何将字体导入wordpress自己怎么优化网站
  • wordpress cn郑州官网关键词优化公司
  • 国外网站鞋子做的好的网站软文代写文案