Blogger Information
Blog 22
fans 0
comment 0
visits 17794
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
HTML DOM querySelector() 方法和 querySelectorAll() 方法
yestrue的博客
Original
678 people have browsed it
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>dom选择器</title>
<style>
ul,ol{
width: 300px;
}
</style>
</head>
<body>
<h3>中学生课程</h3>
<ul>
<li>语文</li>
<li>英语</li>
<li>数学</li>
<li>历史</li>
</ul>
<h3>水果种类</h3>
<ol>
<li>苹果</li>
<li>香蕉</li>
<li>菠萝</li>
<li>橘子</li>
</ol>
<script>
var task = document.querySelector('li');
task.style.backgroundColor = 'skyblue';
var fruit = document.querySelector('ol');
var list = fruit.querySelectorAll('li');
for(var i=0;i<list.length;i++){
list[i].style.backgroundColor = 'pink';
}
</script>
</body>
</html>
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post