/
test.html
66 lines (57 loc) · 1.44 KB
/
test.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
p:after{
content:"hello";
}
p:before{
content:"hi";
}
p:first-letter{
color: green;
}
p:first-line{
color: red;
}
p:first-child{
font-weight: bold;
}
h1:first-child{
color: coral;
}
</style>
</head>
<body>
注册:®<br>
版权:©<br>
商标:™<br>
<div id="div1">
<p>你好</p>
<h1>标题1<small>小标题</small></h1>
<p id="p1">测试</p>
</div>
</body>
<script>
var p1 = document.getElementById('p1');
var div1 = document.getElementById('div1');
div1.removeChild(p1);
var p2 = document.createElement("p");
var text = document.createTextNode("这是js创建的");
var span = document.createElement("span");
var sText = document.createTextNode("测试span");
p2.setAttribute("id","p2");
span.appendChild(sText);
p2.appendChild(text);
p2.appendChild(span);
div1.appendChild(p2);
console.log(p2.parentNode);
console.log(p2.childNodes[1]);
console.log(p2.innerHTML);
console.log(p2.attributes[0]);
console.log(p2.nodeName+p2.nodeValue);
console.log(p2.firstChild.nodeName+p2.firstChild.nodeValue);
</script>
</html>