-
Notifications
You must be signed in to change notification settings - Fork 0
/
DOM 1.2.html
123 lines (119 loc) · 3.58 KB
/
DOM 1.2.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>DOM 1.2</title>
<style>
div,
#tableSample caption {
text-align: center;
}
#tableSample {
width: 100%;
border: 1px solid black;
/* 是否合并单元格边框 */
border-collapse: collapse;
/* 当 border-collapse 设置为 separate 时,这个属性才生效 */
border-spacing: 0.5rem;
text-align: center;
}
#tableSample th,
#tableSample td {
border: 1px solid black;
}
</style>
</head>
<body>
<div>Lighter</div>
<table id="tableSample">
<caption>
表格标题
</caption>
<!--
不能跨越 thead、tbody、tfoot
colspan 跨列
rowspan 跨行
-->
<thead>
<tr>
<th>表头一</th>
<th>表头二</th>
<th>表头三</th>
</tr>
</thead>
<tbody>
<tr>
<td rowspan="2">123</td>
<td>456</td>
<td>789</td>
</tr>
<tr>
<td colspan="3">O*^*O*^*O*^*O*^*O*^*O*^*O*^*O*^*O</td>
</tr>
</tbody>
<tfoot>
<tr>
<td>表脚一</td>
<td>表脚二</td>
<td>表脚三</td>
</tr>
</tfoot>
</table>
</body>
<script>
let headVariable = 'null';
</script>
<script>
console.log(headVariable);
// 动态 JS
function loadScript(jsURL) {
let script = document.createElement('script');
script.className = 'doExp';
script.type = 'text/javascript';
script.src = jsURL;
script.text = 'function tryThis(){alert("doExp");}';
document.body.appendChild(script);
}
loadScript('https://unpkg.com/[email protected]/dist/jquery.js');
setTimeout(function () {
try {
// 可能是浏览器安全限制的原因,不同 script 标签是在一个作用域的...需要通过 eval 函数,将文本信息转化为 js 代码
let doExpJs = document.querySelectorAll('.doExp')[0].innerText;
eval(doExpJs);
tryThis();
} catch (error) {
console.log(error);
}
}, 1000);
// 动态 CSS
function loadStyle(cssURL) {
let style = document.createElement('link'),
isOK = document.createElement('style');
style.id = 'doCSS';
style.rel = 'stylesheet';
style.type = 'text/css';
style.href = cssURL;
isOK.type = 'text/css';
isOK.appendChild(document.createTextNode('html{background:red;}'));
document.head.appendChild(style);
document.head.appendChild(isOK);
}
loadStyle('https://cdn.bootcss.com/bootstrap/4.1.1/css/bootstrap.min.css');
// NodeList、NamedNodeMap、HTMLCollection
// 所有 NodeList 都是动态的,每当文档结构发生变化,他们都会得到更新,以下代码会进入死循环(如果不 break 的话)
// 尽量减少访问 NodeList 的次数。因为每次访问 NodeList,都会运行一次基于文档的查询
var diveles = document.getElementsByTagName('div'),
divele,
i;
for (i = 0; i < diveles.length; i++) {
divele = document.createElement('div');
divele.appendChild(document.createTextNode(i));
document.body.appendChild(divele);
if (i > 9) {
break;
}
}
</script>
</html>