更新时间:2018年08月02日14时41分 来源:传智播客 浏览次数:
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
|
< script > window .onload = function ( ) { / / 设置定时: window .setInterval ( "changeImg()" , 5000 ) ; } var i = 1 ; function changeImg ( ) { i + + ; / / 获得图片的控制权: if ( i > 3 ) { i = 1 ; } var img 1 = document .getElementById ( "img1" ) ; img 1. src = "../img/" + i + ".jpg" ; } < / script > |
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
|
var time; window .onload = function ( ) { time = window .setInterval ( "show()" , 5000 ) ; } / / 显示广告的方法 function show ( ) { / / 获得广告的 div 元素 : var adDiv = document .getElementById ( "adDiv" ) ; adDiv.style. display = "block" ; window .clearInterval ( time ) ; time = window .setInterval ( "hide()" , 5000 ) ; } / / 隐藏广告的方法 : function hide ( ) { / / 获得广告的 div 元素 : var adDiv = document .getElementById ( "adDiv" ) ; adDiv.style. display = "none" ; window .clearInterval ( time ) ; } |
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
|
function tips ( id , content ) { [ / b] document .getElementById ( id + "Span" ) .innerHTML = "<font color='red'>" + content + "</font>" ; } function checkForm ( ) { / / 判断用户名不能为空 : var username = document .getElementById ( "username" ) . value ; if ( username = = "" ) { document .getElementById ( "usernameSpan" ) .innerHTML = "<font color='red'>用户名不能为空!</font>" ; return false ; } var password = document .getElementById ( "password" ) . value ; if ( password = = "" ) { document .getElementById ( "passwordSpan" ) .innerHTML = "<font color='red'>密码不能为空!</font>" ; return false ; } } |
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
|
function changeColor ( ) { [ / b] / / 获得要操作的对象的控制权: var tab 1 = document .getElementById ( "tab1" ) ; / / 获得表格的所有的行数 : var count = tab 1. rows.length; / / 遍历每行 : for ( var i = 0 ;i < count;i + + ) { if ( i % 2 = = 0 ) { / / 偶数行 tab 1. rows[i].style.backgroundColor = "#00FF00" ; } else { / / 奇数行 tab 1. rows[i].style.backgroundColor = "#00FFFF" ; } } } |
01
02
03
04
05
06
07
08
09
10
11
12
|
function changeColor ( ) { [ / b] / / 获得操作的表格的控制权 : var tab 1 = document .getElementById ( "tab1" ) ; / / 获得tbody中的所有的行. var len = tab 1. tBodies[ 0 ].rows.length; for ( var i = 0 ;i < len ;i + + ) { if ( i % 2 = = 0 ) { tab 1. tBodies[ 0 ].rows[i].style.backgroundColor = "green" ; } else { tab 1. tBodies[ 0 ].rows[i].style.backgroundColor = "gold" ; } } } |
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
|
function checkAll ( ) { [ / b] / / 获得上面的复选框 var selectAll = document .getElementById ( "selectAll" ) ; / / 判断这个复选框是否被选中. var ids = document .getElementsByName ( "ids" ) ; if ( selectAll.checked = = true ) { / / 上面复选框被选中:获得下面所有的复选框 , 修改checked属性 for ( var i = 0 ;i < ids.length;i + + ) { ids[i].checked = true ; } } else { / / 上面复选框没有被选中:获得下面所有的复选框 , 修改checked属性 for ( var i = 0 ;i < ids.length;i + + ) { ids[i].checked = false ; } } } |
01
02
03
04
05
06
07
08
09
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
|
/ / 定义数组:二维数组: var arrs = new Array ( 5 ) ; arrs[ 0 ] = new Array ( "杭州市" , "绍兴市" , "温州市" , "义乌市" , "嘉兴市" ) ; arrs[ 1 ] = new Array ( "南京市" , "苏州市" , "扬州市" , "无锡市" ) ; arrs[ 2 ] = new Array ( "武汉市" , "襄阳市" , "荆州市" , "宜昌市" , "恩施" ) ; arrs[ 3 ] = new Array ( "石家庄市" , "唐山市" , "保定市" , "邢台市" , "廊坊市" ) ; arrs[ 4 ] = new Array ( "长春市" , "吉林市" , "四平市" , "延边市" ) ; function changeCity ( value ) { / / 获得到选中的省份的信息. var city = document .getElementById ( "city" ) ; / / 清除第二个列表中的内容 : for ( var i = city .options.length;i > 0 ;i --){ city .options[i] = null; } / / city .options.length = 0 ; / / alert ( value ) ; for ( var i = 0 ;i < arrs.length;i + + ) { if ( value = = i ) { / / 获得所有的市的信息. for ( var j = 0 ;j < arrs[i].length;j + + ) { / / alert ( arrs[i][j] ) ; / / 创建元素: var opEl = document .createElement ( "option" ) ; / / < option > < / option > / / 创建文本节点 : var textNode = document .createTextNode ( arrs[i][j] ) ; / / 将文本的内容添加到option元素中. opEl.appendChild ( textNode ) ; / / 将option的元素添加到第二个列表中. city .appendChild ( opEl ) ; } } } } |