File tree 16 files changed +518
-0
lines changed 16 files changed +518
-0
lines changed Original file line number Diff line number Diff line change 16
16
}
17
17
document . write ( "<br/>" )
18
18
}
19
+ document . getElementsByTagName ( )
19
20
20
21
</ script >
21
22
Original file line number Diff line number Diff line change
1
+ <!DOCTYPE html>
2
+ < html lang ="en ">
3
+ < head >
4
+ < meta charset ="UTF-8 ">
5
+ < title > Title</ title >
6
+ </ head >
7
+ < body >
8
+ < ul id ="u1 ">
9
+ < li id ="a "> javascript</ li >
10
+ < li id ="b "> jquery</ li >
11
+ < li id ="c "> html</ li >
12
+ </ ul >
13
+ < ul id ="u2 ">
14
+ < li id ="d "> css3</ li >
15
+ < li id ="e "> php</ li >
16
+ < li id ="f "> java</ li >
17
+ </ ul >
18
+ < script type ="text/javascript ">
19
+ function get_previousSibling ( n ) {
20
+ var x = n . previousSibling ;
21
+ while ( x && x . nodeType != 1 ) {
22
+ x = x . previousSibling ;
23
+ }
24
+ return x ;
25
+ }
26
+ var x = document . getElementsByTagName ( "li" ) [ 4 ] ;
27
+ document . write ( x . nodeName ) ;
28
+ document . write ( " = " ) ;
29
+ document . write ( x . innerHTML ) ;
30
+ var y = get_previousSibling ( x ) ;
31
+ if ( y != null ) {
32
+ document . write ( "<br/>previousSibling" ) ;
33
+ document . write ( y . nodeName ) ;
34
+ document . write ( " = " ) ;
35
+ document . write ( y . innerHTML ) ;
36
+ document . write ( "<br/>" ) ;
37
+ } else {
38
+ document . write ( "<br/>已经是首节点!" ) ;
39
+ }
40
+ </ script >
41
+
42
+ < script type ="text/javascript ">
43
+ function get_nextSibling ( n ) {
44
+ var x = n . nextSibling ;
45
+ while ( x && x . nodeType != 1 ) {
46
+ x = x . nextSibling ;
47
+ }
48
+ return x ;
49
+ }
50
+
51
+ var x = document . getElementsByTagName ( "li" ) [ 0 ] ;
52
+ document . write ( x . nodeName ) ;
53
+ document . write ( " = " ) ;
54
+ document . write ( x . innerHTML ) ;
55
+ var y = get_nextSibling ( x ) ;
56
+
57
+ if ( y != null ) {
58
+ document . write ( "<br />nextsibling: " ) ;
59
+ document . write ( y . nodeName ) ;
60
+ document . write ( " = " ) ;
61
+ document . write ( y . innerHTML ) ;
62
+ } else {
63
+ document . write ( "<br>已经是最后一个节点" ) ;
64
+ }
65
+ </ script >
66
+
67
+
68
+ </ body >
69
+ </ html >
Original file line number Diff line number Diff line change
1
+ <!DOCTYPE html>
2
+ < html lang ="en ">
3
+ < head >
4
+ < meta charset ="UTF-8 ">
5
+ < title > Title</ title >
6
+ </ head >
7
+ < body >
8
+ < ul id ="test ">
9
+ < li > JavaScript</ li >
10
+ < li > HTML</ li >
11
+ </ ul >
12
+ < script type ="text/javascript ">
13
+ var otest = document . getElementById ( 'test' ) ;
14
+ var newnode = document . createElement ( 'li' ) ;
15
+ newnode . innerHTML = "PHP世界上最好的语言!" ;
16
+ otest . appendChild ( newnode ) ;
17
+
18
+ </ script >
19
+
20
+ </ body >
21
+ </ html >
Original file line number Diff line number Diff line change
1
+ <!DOCTYPE html>
2
+ < html lang ="en ">
3
+ < head >
4
+ < meta charset ="UTF-8 ">
5
+ < title > Title</ title >
6
+ </ head >
7
+ < body >
8
+ < ul id ="test ">
9
+ < li > JavaScript</ li >
10
+ < li > HTML</ li >
11
+ </ ul >
12
+ < script type ="text/javascript ">
13
+ var otest = document . getElementById ( 'test' ) ;
14
+ var node = document . getElementsByTagName ( 'li' ) [ 0 ] ;
15
+ var newnode = document . createElement ( 'li' ) ;
16
+ newnode . innerHTML = 'php'
17
+ otest . insertBefore ( newnode , node ) ;
18
+ </ script >
19
+
20
+ </ body >
21
+ </ html >
Original file line number Diff line number Diff line change
1
+ <!DOCTYPE html>
2
+ < html lang ="en ">
3
+ < head >
4
+ < meta charset ="UTF-8 ">
5
+ < title > Title</ title >
6
+ </ head >
7
+ < body >
8
+ < div id ="content ">
9
+ < h1 > html</ h1 >
10
+ < h1 > php</ h1 >
11
+ < h1 > javascript</ h1 >
12
+ < h1 > jquery</ h1 >
13
+ < h1 > java</ h1 >
14
+ </ div >
15
+
16
+ < script type ="text/javascript ">
17
+ function clearText ( ) {
18
+ var content = document . getElementById ( "content" ) ;
19
+ // 在此完成该函数'
20
+ var x = content . removeChild ( content . childNodes [ 1 ] ) ;
21
+ document . write ( "删除节点的内容为:" + x . innerHTML ) ;
22
+
23
+ // 遍历节点
24
+ for ( var i = 0 ; i < content . length ; i ++ ) {
25
+ document . write ( content [ i ] . nodeName + "<br/>" ) ;
26
+ document . write ( content [ i ] . nodeType + "<br/>" ) ;
27
+ document . write ( content [ i ] . nodeValue + "<br/>" ) ;
28
+ }
29
+
30
+ }
31
+ </ script >
32
+
33
+ < button onclick ="clearText() "> 清除节点内容</ button >
34
+
35
+ </ body >
36
+ </ html >
Original file line number Diff line number Diff line change
1
+ <!DOCTYPE html>
2
+ < html lang ="en ">
3
+ < head >
4
+ < meta charset ="UTF-8 ">
5
+ < title > Title</ title >
6
+ </ head >
7
+ < body >
8
+
9
+ < div >
10
+ < b id ="oldnode "> JavaScript</ b >
11
+ 是一个很常用的技术,为网页添加动态效果。
12
+ </ div >
13
+
14
+ < a href ="javascript:replaceMessage() "> 将加粗改为斜体</ a >
15
+
16
+ < script type ="text/javascript ">
17
+ function replaceMessage ( ) {
18
+ var newnode = document . createElement ( 'i' ) ;
19
+ var newnodetext = document . createTextNode ( 'JavaScript' ) ;
20
+ newnode . appendChild ( newnodetext ) ;
21
+ var oldnode = document . getElementById ( 'oldnode' ) ;
22
+ oldnode . parentNode . replaceChild ( newnode , oldnode ) ;
23
+ }
24
+ </ script >
25
+ </ body >
26
+ </ html >
Original file line number Diff line number Diff line change
1
+ <!DOCTYPE html>
2
+ < html lang ="en ">
3
+ < head >
4
+ < meta charset ="UTF-8 ">
5
+ < title > Title</ title >
6
+ </ head >
7
+ < body >
8
+ < script type ="text/javascript ">
9
+ var body = document . body ;
10
+ var input = document . createElement ( "input" ) ;
11
+ input . type = "button" ;
12
+ input . value = '创建一个按钮!' ;
13
+ body . appendChild ( input ) ;
14
+
15
+ document . write ( "<br/>" ) ;
16
+
17
+ </ script >
18
+
19
+ < script type ="text/javascript ">
20
+ var body = document . body ;
21
+ var btn = document . createElement ( 'input' ) ;
22
+ btn . setAttribute ( "type" , "text" ) ;
23
+ btn . setAttribute ( "name" , "p" ) ;
24
+ btn . setAttribute ( "value" , "使用setAttribute" ) ;
25
+ btn . setAttribute ( "onclick" , "javascript:alert('This is a text!');" ) ;
26
+ body . appendChild ( btn ) ;
27
+ </ script >
28
+
29
+
30
+ </ body >
31
+ </ html >
Original file line number Diff line number Diff line change
1
+ <!DOCTYPE html>
2
+ < html lang ="en ">
3
+ < head >
4
+ < meta charset ="UTF-8 ">
5
+ < title > Title</ title >
6
+ </ head >
7
+ < body >
8
+ < script type ="text/javascript ">
9
+ var main = document . body ;
10
+ //创建链接
11
+ function createa ( url , text ) {
12
+ var a = document . createElement ( 'a' ) ;
13
+ a . href = url ;
14
+ a . style . color = 'red' ;
15
+ a . innerHTML = text ;
16
+ main . appendChild ( a ) ;
17
+
18
+
19
+ }
20
+ // 调用函数创建链接
21
+ createa ( "https://www.baidu.com" , "众里寻他千百度,蓦然回首他却灯火阑珊" ) ;
22
+
23
+ </ script >
24
+ </ body >
25
+ </ html >
Original file line number Diff line number Diff line change
1
+ <!DOCTYPE html>
2
+ < html lang ="en ">
3
+ < head >
4
+ < meta charset ="UTF-8 ">
5
+ < title > Title</ title >
6
+ </ head >
7
+ < style type ="text/css ">
8
+
9
+ .message {
10
+ width : 200px ;
11
+ height : 100px ;
12
+ background-color : # CCC ;
13
+ }
14
+
15
+ </ style >
16
+ < body >
17
+ < script type ="text/javascript ">
18
+ var element = document . createElement ( "p" ) ;
19
+ element . className = 'message' ;
20
+ var textnode = document . createTextNode ( "I love JavaScript!" ) ;
21
+ element . appendChild ( textnode ) ;
22
+ document . body . appendChild ( element ) ;
23
+ </ script >
24
+
25
+
26
+ </ body >
27
+ </ html >
Original file line number Diff line number Diff line change
1
+ <!DOCTYPE html>
2
+ < html lang ="en ">
3
+ < head >
4
+ < meta charset ="UTF-8 ">
5
+ < title > Title</ title >
6
+ </ head >
7
+ < body >
8
+ < script type ="text/javascript ">
9
+ var w = document . documentElement . clientWidth || document . body . clientWidth ;
10
+
11
+ var h = document . documentElement . clientHeight || document . body . clientHeight ;
12
+
13
+ document . write ( "宽度:" + w + "<br/>" ) ;
14
+
15
+ document . write ( "高度:" + h + "<br/>" ) ;
16
+
17
+ </ script >
18
+
19
+
20
+ </ body >
21
+ </ html >
Original file line number Diff line number Diff line change
1
+ <!DOCTYPE html>
2
+ < html lang ="en ">
3
+ < head >
4
+ < meta charset ="UTF-8 ">
5
+ < title > Title</ title >
6
+ </ head >
7
+ < script type ="text/javascript ">
8
+
9
+ window . onload = function ( ) {
10
+ Hightlight ( ) ;
11
+ }
12
+
13
+ // 隔行换色
14
+ function Hightlight ( ) {
15
+ var tbody = document . getElementById ( 'table' ) . lastChild ;
16
+ var trs = tbody . getElementsByTagName ( 'tr' ) ;
17
+ for ( var i = 1 ; i < trs . length ; i ++ ) {
18
+ trs [ i ] . onmouseover = function ( ) {
19
+ this . style . backgroundColor = "#f2f2f2" ;
20
+ }
21
+ trs [ i ] . onmouseout = function ( ) {
22
+ this . style . backgroundColor = "#fff" ;
23
+ }
24
+ }
25
+ }
26
+ // 添加
27
+ function addOne ( obj ) {
28
+
29
+ var tbody = document . getElementById ( 'table' ) . lastChild ;
30
+ var tr = document . createElement ( 'tr' ) ;
31
+
32
+ // 第一个
33
+ var td = document . createElement ( 'td' ) ;
34
+ td . innerHTML = "<input type='text'/>" ;
35
+ tr . appendChild ( td ) ;
36
+
37
+ // 第二个
38
+ td = document . createElement ( "td" ) ;
39
+ td . innerHTML = "<input type='text'/>" ;
40
+ tr . appendChild ( td ) ;
41
+
42
+ td = document . createElement ( "td" ) ;
43
+ td . innerHTML = "<a href='javascript:;' onclick='deleteRow(this)'>删除</a>" ;
44
+ tr . appendChild ( td ) ;
45
+
46
+ tbody . appendChild ( tr ) ;
47
+ Hightlight ( ) ;
48
+ }
49
+ // 创建删除函数
50
+ function deleteRow ( obj ) {
51
+ var tbody = document . getElementById ( 'table' ) . lastChild ;
52
+ var tr = obj . parentNode . parentNode ;
53
+ tbody . removeChild ( tr ) ;
54
+ }
55
+
56
+ </ script >
57
+ </ head >
58
+ < body >
59
+ < table border ="1 " width ="50% " id ="table ">
60
+ < tr >
61
+ < th > 学号</ th >
62
+ < th > 姓名</ th >
63
+ < th > 操作</ th >
64
+ </ tr >
65
+
66
+ < tr >
67
+ < td > xh001</ td >
68
+ < td > 王小明</ td >
69
+ < td > < a href ="javascript:; "> 删除</ a > </ td > <!--在删除按钮上添加点击事件 -->
70
+ </ tr >
71
+
72
+ < tr >
73
+ < td > xh002</ td >
74
+ < td > 刘小芳</ td >
75
+ < td > < a href ="javascript:; "> 删除</ a > </ td > <!--在删除按钮上添加点击事件 -->
76
+ </ tr >
77
+
78
+ </ table >
79
+ < input type ="button " value ="添加一行 " onclick ="addOne() "/> <!--在添加按钮上添加点击事件 -->
80
+ </ body >
81
+ </ html >
You can’t perform that action at this time.
0 commit comments