当前位置:网站首页>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>
边栏推荐
- Computer network: sorting out common network interview questions (I)
- Cereals Mall - Distributed Advanced p129~p339 (end)
- Swagger2 reports an error illegal DefaultValue null for parameter type integer
- 谷粒商城--分布式高级篇P129~P339(完结)
- [translation] a GPU approach to particle physics
- 快速幂模板求逆元,逆元的作用以及例题【第20届上海大学程序设计联赛夏季赛】排列计数
- 助力安全人才专业素养提升 | 个人能力认证考核第一阶段圆满结束!
- How to do smoke test
- The second day of rhcsa study
- Is not a drawable (color or path): the vector graph downloaded externally cannot be called when it is put into mipmap, and the calling error program crashes
猜你喜欢

LeetCode_双指针_中等_61. 旋转链表
![[玩转Linux] [Docker] MySQL安装和配置](/img/04/6253ef9fdf7d2242b42b4c7fb2c607.png)
[玩转Linux] [Docker] MySQL安装和配置

Black Horse - - Redis Chapter

Xingnuochi technology's IPO was terminated: it was planned to raise 350million yuan, with an annual revenue of 367million yuan

JDBC详解
In depth analysis, Android interview real problem analysis is popular all over the network

如何自定义动漫头像?这6个免费精品在线卡通头像生成器,看一眼就怦然心动!

潇洒郎: AttributeError: partially initialized module ‘cv2‘ has no attribute ‘gapi_wip_gst_GStreamerPipe

Detailed idea and code implementation of infix expression to suffix expression

LeetCode-1279. Traffic light intersection
随机推荐
Php+redis realizes the function of canceling orders over time
The dplyr package of R language performs data grouping aggregation statistical transformations and calculates the grouping mean of dataframe data
DaGAN论文解读
Actf 2022 came to a successful conclusion, and 0ops team won the second consecutive championship!!
受益匪浅,安卓面试问题
Using clip path to draw irregular graphics
Simple understanding of MySQL database
LeetCode_格雷编码_中等_89.格雷编码
A full set of teaching materials, real questions of Android interview of 7 major manufacturers including Alibaba Kwai pinduoduo
ACTF 2022圆满落幕,0ops战队二连冠!!
保证接口数据安全的10种方案
LeetCode-1279. 红绿灯路口
Solution of intelligent management platform for suppliers in hardware and electromechanical industry: optimize supply chain management and drive enterprise performance growth
通俗的讲解,带你入门协程
In 50W, what have I done right?
ROS custom message publishing subscription example
打家劫舍III[后序遍历与回溯+动态规划]
A popular explanation will help you get started
冒烟测试怎么做
Solution of commercial supply chain management platform for packaging industry: layout smart supply system and digitally integrate the supply chain of packaging industry