1. dom节点
1.1 dom节点获取
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>DOM document object model 文档顶级节点</title>
</head>
<body>
<div id="box">
<p class="p1" >张三</p>
<p class="p2">李四</p>
<p class="p3">赵刘</p>
<p name="ceshi1"></p>
<p name="ceshi1"></p>
</div>
<div>
<input type="text" name="username" />
<input type="password" name="pwd" />
<p1>112233</p1>
<box>55666</box>
</div>
<script>
console.log(document)
var box = document.getElementById("box");
console.log(box);
var p2 = document.getElementsByClassName("p2");
console.log(p2 , typeof(p2));
lisi = p2[0];
console.log(lisi)
wangwu = p2[1];
console.log(wangwu);
var p = document.getElementsByTagName("p");
console.log(p)
console.log(p[1])
var ceshi1 = document.getElementsByName("username")[0];
console.log(ceshi1);
var p1 = document.querySelector(".p1");
console.log(p1)
var box = document.querySelector("#box");
console.log(box)
var input = document.querySelector("input");
console.log(input);
var all = document.querySelectorAll("input[name=username]")[0];
console.log(all);
</script>
</body>
</html>
1.2 节点元素层级关系
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>节点元素层级关系</title>
</head>
<body>
<div id="box">
<p>
<input type="text" name="username" />
<input type="password" name="pwd" />
</p>
<p class="p1" >张三</p>
<p class="p2">李四</p>
<p class="p3">赵刘</p>
<p name="ceshi1"></p>
<p name="ceshi1"></p>
</div>
<script>
console.log(document)
console.log(document.documentElement);
console.log(document.documentElement.children)
var html_children = document.documentElement.children
console.log(html_children)
body = html_children[1];
console.log(body);
var div = body.children[0]
console.log(div);
var p0 = div.children[0]
console.log(p0)
var input = p0.children
console.log(input)
var input1 = input[0]
console.log(input1)
console.log(input1.nextSibling.nextSibling);
var input2 = input1.nextElementSibling;
console.log(input2);
console.log(input2.previousSibling)
console.log(input2.previousElementSibling)
console.log(input2.parentElement)
</script>
</body>
</html>
2. 全选_反选_不选
3. 模态框
|