当前位置:网站首页>Dom 操作
Dom 操作
2022-07-06 11:35:00 【wangatong】
用Id
var a = document.getElementById("id 名")
用 class取到的是数组
var a = documen.getElementsByClassName("class 名")
用标签获取到的是数组
var a = document.getElementsByTagName ("标签名")
用 name取到的是数组
var a = document.getElementsByName( "name名" )
用选择符querySelectorAll
document.querySelector("p");
事件
onmouseover,onmouseout,onclick,
修改样式
a.style.
Document:根节点
parentNode: 获取父节点
childNodes: 获取所有的子节点
firstChild:第一个子节点
lastChild:最后一个子节点
<p id="p1" class="p1">点击</p>
<div id="div1"></div>
<script>
// let p = document.getElementById('p1') //id
// let p = document.querySelector("#p1")
// let p = document.querySelectorAll("#p1")[0]
// let p = document.getElementsByTagName("p")[0] //标签
let p = document.getElementsByClassName('p1')[0] //class类
p.onclick = function(){
console.log(111)
}
p.onmouseover = function(){
console.log(222)
}
p.onmouseout = function(){
console.log(333)
}
let div = document.createElement("p") //创建元素节点
let content = "dfsfsdfsf"
let txt = document.createTextNode(content) //创建文本节点
div.appendChild(txt) //添加子节点
let div1 = document.getElementById("div1")
div1.appendChild(div)
// div1.removeChild(div) //移除节点
let val = div.parentNode.getAttribute("id") //获取父节点,获取属性值
// alert(val)
div.parentNode.setAttribute("name","12") //设置属性
// prompt("What's your name?", "Default")
// var re = confirm("要进行删除操作吗?");
// if(re == false){
// console.log('false')
// }else{
// console.log('true')
// }
console.log(navigator.language)
console.log(document.title)
console.log(document.head)
</script>
边栏推荐
- IC设计流程中需要使用到的文件
- 零基础入门PolarDB-X:搭建高可用系统并联动数据大屏
- 包装行业商业供应链管理平台解决方案:布局智慧供应体系,数字化整合包装行业供应链
- Spark foundation -scala
- First day of rhcsa study
- 黑马--Redis篇
- Swagger2 reports an error illegal DefaultValue null for parameter type integer
- 全套教学资料,阿里快手拼多多等7家大厂Android面试真题
- 深入分析,Android面试真题解析火爆全网
- ROS custom message publishing subscription example
猜你喜欢
零基础入门PolarDB-X:搭建高可用系统并联动数据大屏
Take a look at how cabloyjs workflow engine implements activiti boundary events
How to access localhost:8000 by mobile phone
助力安全人才专业素养提升 | 个人能力认证考核第一阶段圆满结束!
Druid database connection pool details
How to type multiple spaces when editing CSDN articles
Countdown 2 days | live broadcast preview of Tencent cloud message queue data import platform
JDBC details
学习探索-无缝轮播图
PMP每日一练 | 考试不迷路-7.6
随机推荐
Sanmian ant financial successfully got the offer, and has experience in Android development agency recruitment and interview
ACTF 2022圆满落幕,0ops战队二连冠!!
学习探索-函数防抖
PMP practice once a day | don't get lost in the exam -7.6
Carte de réflexion + code source + notes + projet, saut d'octets + jd + 360 + tri des questions d'entrevue Netease
R language ggplot2 visual time series histogram: visual time series histogram through two-color gradient color matching color theme
MRO industrial products enterprise procurement system: how to refine procurement collaborative management? Industrial products enterprises that want to upgrade must see!
1805. 字符串中不同整数的数目
【翻译】云原生观察能力微调查。普罗米修斯引领潮流,但要了解系统的健康状况仍有障碍...
如何自定义动漫头像?这6个免费精品在线卡通头像生成器,看一眼就怦然心动!
GCC [7] - compilation checks the declaration of functions, and link checks the definition bugs of functions
第五期个人能力认证考核通过名单公布
Mysql Information Schema 学习(一)--通用表
zabbix 代理服务器 与 zabbix-snmp 监控
受益匪浅,安卓面试问题
Documents to be used in IC design process
English topic assignment (25)
驼峰式与下划线命名规则(Camel case With hungarian notation)
助力安全人才专业素养提升 | 个人能力认证考核第一阶段圆满结束!
A full set of teaching materials, real questions of Android interview of 7 major manufacturers including Alibaba Kwai pinduoduo