-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtext.html
More file actions
46 lines (41 loc) · 1.24 KB
/
text.html
File metadata and controls
46 lines (41 loc) · 1.24 KB
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
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
<style rel="stylesheet" type="text/css">
.Message {
background: red;
width: 500px;
height: 500px;
}
</style>
</head>
<body>
</body>
<script type="text/javascript">
//normalize合并节点
// var element = document.createElement('div');
// element.className = 'Message';
// var textNode = document.createTextNode('Hello World');
// element.appendChild(textNode);
// var anthorTextNode = document.createTextNode(' hi Yahoo!');
// element.appendChild(anthorTextNode);
//
// document.body.appendChild(element);
//
// alert(element.childNodes.length); //2
// element.normalize();
// alert(element.childNodes.length); //1
// alert(element.firstChild.nodeValue);
///splitText方法,分割节点
var element = document.createElement('div');
element.className = 'Message';
var textNode = document.createTextNode('Hello World');
element.appendChild(textNode);
var newNode = element.firstChild.splitText(5);
alert(element.firstChild.nodeValue); //"Hello"
alert(newNode.nodeValue); //" world!"
alert(element.childNodes.length);
</script>
</html>