js_实例

新开普各种js实例的讲解

1、array根据设定的时间来显示图片

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<body onload="show()">
<center>
<img src=images/p1.jpg width=800 height=600 id=photo>
</body>
<script language="javascript">
function show()
{
var myphoto=document.getElementById("photo");
var s=myphoto.src.split("images/"); //s[0]="images/"; s[1]="p1.jpg";
var number=s[1].charAt(1);
number++;
if(number>5)
number=1;
myphoto.src="images/p"+number+".jpg";
setTimeout("show()",1000);
}
</script>

2、array选择图片

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
<meta charset=utf-8>
<select id=bg name=bg onchange="show(this)">
<option value="">-请选择一张</option>
<option value=1>图片1</option>
<option value=2>图片2</option>
<option value=3>图片3</option>
<option value=4>图片4</option>
<option value=5>图片5</option>
</select>
<hr><p align=center>
<div id=photo></div>
<script language="javascript">
function show(o)
{
if(o.value!="")
{
document.getElementById("photo").innerHTML="<img src=images/p"+o.value+".jpg width=600>";
}
else
{
location.href="array3.html";
}
}
</script>

3、display_侧边下拉菜单

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
<meta charset=utf-8>
<style type="text/css">
li
{
list-style:none;
}
</style>
[ <a href=# id=mylink onclick="showall()">全部展开</a> ]<hr>
<a href=# onclick="op(1)" id="a1">用户管理</a><p>
<ul id=1>
<li><a href=#>用户添加</a></li>
<li><a href=#>用户管理</a></li>
</ul>
<a href=# onclick="op(2)" id="a2">商品管理</a><p>
<ul id=2 style="display:none">
<li><a href=#>商品添加</a></li>
<li><a href=#>商品管理</a></li>
</ul>
<a href=# onclick="op(3)" id="a3">订单管理</a><p>
<ul id=3 style="display:none">
<li><a href=#>订单添加</a></li>
<li><a href=#>订单管理</a></li>
</ul>
<script language="javascript">
function op(id)
{
var o=document.getElementById(id);
for(i=1;i<=3;i++){
if(i==id){
if(o.style.display=="none")
o.style.display="block";
else
o.style.display="none";
}else{
document.getElementById(i).style.display="none";
}
}
}
/*function op(a,id){
var aa=document.getElementById(a);
var idd=document.getElementById(id);
aa.onmouseover=function(){
idd.style.display="block";
}
aa.onmouseout=function(){
idd.style.display="none";
}
}
op("a1","1");op("a2","2");
op("a3","3");*/
function showall()
{
var my=document.getElementById("mylink");
if(my.innerHTML=="全部展开")
{
my.innerHTML="全部收回";
for(i=1;i<=3;i++)
{
document.getElementById(i).style.display="block";
}
}
else
{
my.innerHTML="全部展开";
for(i=1;i<=3;i++)
{
document.getElementById(i).style.display="none";
}
}
}
</script>

4、进度

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
<meta charset=utf-8>
<style type="text/css">
.my1
{
border:2px solid #00FF00;
width:200px;
height:22px;
}
</style>
<body onload="mystart()">
<div class=my1><img src=images/border.png width=0 height=20 id=photo> <span id=current></span></div>
</body>
<script language="javascript">
function mystart()
{
var o=document.getElementById("photo");
o.width=o.width+1;
document.getElementById("current").innerHTML=o.width+"%";
if(o.width>200)
o.stop();
setTimeout("mystart()",10);
}
</script>

5、简单的计算器功能实现

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
第一个数:<input type=text id=first><p>
第二个数:<input type=text id=second><p>
<input type=button value=+ onclick="op('+')">
<input type=button value=- onclick="op('-')">
<input type=button value=* onclick="op('*')">
<input type=button value=/ onclick="op('/')"><p>
结果:<input type=text id=result>
<script language="javascript">
function op(fuhao)
{
var first=parseInt(document.getElementById("first").value);
var second=parseInt(document.getElementById("second").value);
switch(fuhao)
{
case '+':
var value=first+second;
document.getElementById("result").value=value;
break;
case '-':
var value=first-second;
document.getElementById("result").value=value;
break;
case '*':
var value=first*second;
document.getElementById("result").value=value;
break;
case '/':
if(second!=0)
{
var value=first/second;
document.getElementById("result").value=value;
}
else
{
alert("除数不能为0!");
document.getElementById("second").value="";
document.getElementById("second").focus();
}
break;
}
}
</script>

6、mouseover和mouseout轮播图的使用

1
2
<meta charset=utf-8>
<marquee onmouseover="this.stop()" onmouseout="this.start()"><img src="images/78.gif"></marquee>

7、onclick2-value的值加减操作

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<meta charset=utf-8>
<p>订购数量</p>
<input type="button" value="<" onclick="jian('<')"><input type="text" id="num" value=1><input type="button" value=">" onclick="add('>')">
<script>
var o=document.getElementById('num');
function jian(t){
if(t=='<'){
if(o.value>1){
o.value--;
}
}
}
function add(t){
if(t=='>'){
o.value++;
}
}
</script>

8、协议同意按钮可用

1
2
3
4
5
6
7
8
9
10
11
12
13
<meta charset="utf-8">
<input type=checkbox id="a" onclick="check(this)" value=""><p>我已同意此条协议。<p><br>
<input type="button" value="确定,下一步" disabled id="ok" >
<script>
function check(o){
if(o.checked==true){
document.getElementById('ok').disabled=false;
}
else
document.getElementById('ok').disabled=true;
}
</script>

9、onfocus和onblur文本框背景变色

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
<meta charset=utf-8>
<style type="text/css">
.a1 /*定义名为a1的类选择符*/
{
background:#FFFF00;
border:2px solid #FF0000;
}
.a2
{
background:#FFFFFF;
border:1px solid #CCCCCC;
}
</style>
用户名:<input type=text id=username onfocus="op1()" onblur="op2()">
<script language="javascript">
function op1()
{
var o=document.getElementById("username");
o.className="a1";
}
function op2()
{
var o=document.getElementById("username");
o.className="a2";
}
</script>

10、onmouseover_显示大图

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
<meta charset=utf-8>
<body bgcolor="#ccc">
<table border=0 width=960 style="margin:0 auto;">
<tr align=center>
<td><img src="images/p1.jpg" width=200 height=200 onmouseover="show('p1')" onmouseout="out('p1')"></td>
<td><img src="images/p2.jpg" width=200 height=200 onmouseover="show('p2')" onmouseout="out('p2')"></td>
<td><img src="images/p3.jpg" width=200 height=200 onmouseover="show('p3')" onmouseout="out('p3')"></td>
<td><img src="images/p4.jpg" width=200 height=200 onmouseover="show('p4')" onmouseout="out('p4')"></td>
<td><img src="images/p5.jpg" width=200 height=200 onmouseover="show('p5')" onmouseout="out('p5')"></td>
</tr>
<tr align="center">
<td colspan=5><img src="images/space.jpg" width=750 id="photo"></td>
</tr>
</table>
<script>
function show(o){
var p=document.getElementById('photo');
p.src="images/"+o+".jpg";
}
function out(i){
var p=document.getElementById('photo');
p.src="images/space.jpg";
}
</script>
</body>

11、onmouseover_改变背景颜色

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
<meta charset=utf-8>
<table border=1 width=20% align=center>
<tr align=center bgcolor="#ccc" onmouseover="change(this)" onmouseout="unchange(this)">
<th>姓名</th>
<th>年龄</th>
<th>成绩</th>
</tr>
<tr align=center onmouseover="mopen(this)" onmouseout="unchange(this)">
<td>秀秀</td>
<td>10</td>
<td>100</td>
</tr>
<tr align=center onmouseover="mopen(this)" onmouseout="unchange(this)">
<td>栗子</td>
<td>17</td>
<td>90</td>
</tr>
<tr align=center onmouseover="mopen(this)" onmouseout="unchange(this)">
<td>方丽</td>
<td>15</td>
<td>89</td>
</tr>
</table>
<script>
function change(t){
t.style.background="#FFF8DC";
t.style.color="#BC8F8F";
t.style.cursor="hand";
}
function unchange(k){
k.style.background="#FFFfff";
k.style.color="#333";
}
function mopen(i){
i.style.background="#F5F5DC";
i.style.color="#CD5C5C";
i.style.cursor="hand";
}
</script>

12、prompt_阶乘

1
2
3
4
5
6
7
8
9
10
11
12
<meta charset=utf-8>
<input type="button" value="点击计算输入的数字的阶乘" onclick="my()">
<script>
function my(){
var s=prompt("请输入一个数字");
var n=1;
for(i=1;i<=s;i++){
n=n*i;
}
alert(s+"的阶乘是:"+n);
}
</script>

13、tab_menu_display菜单

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
<meta charset=utf-8>
<style>
a
{
width:150px;
height:30px;
line-height:30px;
float:left;
text-decoration:none;
color:#ccc;
}
a:hover{
color:#ff0000;
}
.a1{
background:#fcfcfc;
border-top:1px solid red;
border-left:1px solid red;
border-right:1px solid red;
}
.a2{
border-bottom:1px solid red;
}
#bank,#zhifu{
width:300px;
height:150px;
border-left:1px solid red;
border-bottom:1px solid red;
border-right:1px solid red;
}
</style>
<table align=center cellspacing=0 cellpadding=0>
<tr align=center>
<td >
<a href="#" class="a1" id="bank1" onclick="op('bank')">银行卡支付</a>
<a href="#" onclick="op('bank')" id="bank2" style="display:none;" class=a2>银行卡支付</a>
</td>
<td >
<a href="#" class="a1" id="zhifu1" onclick="op('zhifu')" style="display:none;">支付宝支付</a>
<a href="#" onclick="op('zhifu')" id="zhifu2" class=a2>支付宝支付</a>
</td>
</tr>
<tr>
<td colspan=2>
<div id="bank">
<table width=100% align=center>
<tr>
<td>银行选择</td>
<td><select>
<option>中国工商银行</option>
<option>中国农业银行</option>
<option>中国建设银行</option>
<option>中国银行</option>
</select></td>
</tr>
<tr>
<td>账号</td>
<td><input type="text"></td>
</tr>
<tr>
<td>密码</td>
<td><input type="password"></td>
</tr>
<tr colspan=2>
<td><input type="submit" value="确定"></td><td><input type="reset" value="取消"></td>
</tr>
</table>
</div>
<div id="zhifu" style="display:none;">
<table width=100% align=center>
<tr>
<td>支付宝账号</td>
<td><input type="text"></td>
</tr>
<tr>
<td>密码</td>
<td><input type="password"></td>
</tr>
<tr colspan=2>
<td><input type="submit" value="确定"></td><td><input type="reset" value="取消"></td>
</tr>
</table>
</div>
</td>
</tr>
</table>
<script>
function op(t){
if(t=="bank") //证明点的是银行卡支付
{
document.getElementById("bank1").style.display="block";
document.getElementById("bank2").style.display="none";
document.getElementById("zhifu1").style.display="none";
document.getElementById("zhifu2").style.display="block";
document.getElementById("bank").style.display="block";
document.getElementById("zhifu").style.display="none";
}
else if(t=="zhifu")
{
document.getElementById("bank1").style.display="none";
document.getElementById("bank2").style.display="block";
document.getElementById("zhifu1").style.display="block";
document.getElementById("zhifu2").style.display="none";
document.getElementById("bank").style.display="none";
document.getElementById("zhifu").style.display="block";
}
}
</script>

14、tabmenu下拉菜单

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
<meta charset=utf-8>
<style>
a{
display:block;
text-decoration:none;
color:#fff;
background:#0663a8;
margin-left:2px;
width:150px;
height:40px;
/*float:left;*/
text-align:center;
line-height:40px;
}
a:hover{
width:150px;
height:40px;
color:#fff;
background:#ff0000;
}
</style>
<table align=center cellpadding=0 cellspacing=0>
<tr>
<td><a href="#" onmouseover="ov(1)" onmouseout="clos(1)">文件</a></td>
<td><a href="#" onmouseover="ov(2)" onmouseout="clos(2)">编辑</a></td>
<td><a href="#" onmouseover="ov(3)" onmouseout="clos(3)">查看</a></td>
</tr>
<tr>
<td ><div style="display:none;" id=1>
<a href="#" onmouseover="ov(1)" onmouseout="clos(1)">打开。。</a>
<a href="#" onmouseover="ov(1)" onmouseout="clos(1)">保存</a>
<a href="#" onmouseover="ov(1)" onmouseout="clos(1)">另存为</a></div></td>
<td><div style="display:none;" id=2>
<a href="#" onmouseover="ov(2)" onmouseout="clos(2)">复制</a>
<a href="#" onmouseover="ov(2)" onmouseout="clos(2)">粘贴</a>
<a href="#" onmouseover="ov(2)" onmouseout="clos(2)">剪切</a></div></td>
<td >
<div style="display:none;" id="3">
<a href="#" onmouseover="ov(3)" onmouseout="clos(3)">字体</a>
<a href="#" onmouseover="ov(3)" onmouseout="clos(3)">颜色</a>
<a href="#" onmouseover="ov(3)" onmouseout="clos(3)">换行符</a>
</div>
</td>
</tr>
</table>
<script>
function ov(id){
document.getElementById(id).style.display="block";
}
function clos(id){
document.getElementById(id).style.display="none";
}
</script>

15、tab_显示内容

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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
<meta charset=utf-8>
<style>
.contain{
width:504px;
height:auto;
margin:0 auto;
border:1px solid #ccc;
}
a{
text-decoration:none;
}
ul{
list-style:none;
}
.a1{
float:left;
width:100px;
height:30px;
line-height:30px;
text-align:center;
border-top:4px solid blue;
border-left:1px solid #ccc;
border-right:1px solid #ccc;
}
.aa1{
width:100px;
height:30px;
float:left;
line-height:30px;
text-align:center;
border-bottom:4px solid blue;
border-top:1px solid #ccc;
border-right:1px solid #ccc;
}
.a2{
border-bottom:4px solid blue;
border-top:1px solid #ccc;
border-right:1px solid #ccc;
width:200px;
height:30px;
font-size:3px;
}
.a2 a{
position:relative;
right:-80px;
margin:3px;
}
/*内容*/
.con_1{
width:504px;
/*border:1px solid black;*/
}
.con_2{
width:484px;
/*border:1px solid black;*/
margin-left:18px;
}
.t2{
margin-top:10px;
}
#carr img,#twoo img,#jiangg img{
width:100px;
height:89px;
}
.im{
margin-left:-7px;
float:left;
width:100px;
height:auto;
}
.c1{
color:rgb(18,1,159);
font-weight:bold;
}
.content1{
float:left;
}
.content ul li{
padding-left:10px;
}
.t3{
margin-left:20px;
}
.t4{
margin-left: 106px;
height:100px;
margin:0 auto;
}
.con{
margin-top:7px;
margin-left:-9px;
}
</style>
<div class="contain">
<table align=center border=0 cellpadding=0 cellspacing=0>
<tr>
<td >
<a href="#" id="car1" onclick="op('car')" class="a1"><img src="images/img1.jpg">汽车</a>
<a href="#" id="car2" onclick="op('car')" style="display:none;" class="aa1"><img src="images/img1.jpg">汽车</a></td>
<td ><a href="#" id="jiang1" onclick="op('jiang')" class="a1" style="display:none;">降价</a>
<a href="#" id="jiang2" onclick="op('jiang')" class="aa1">降价</a></td>
<td ><a href="#" id="two1" onclick="op('two')" class="a1" style="display:none;">二手车</a>
<a href="#" id="two2" onclick="op('two')" class="aa1">二手车</a></td>
<td class="a2" colspan=3>
<a href="#" >查违章|</a><span style="float:left;margin-left:-20px;"></span>
<a href="#">优惠|</a><span style="float:left;margin-left:-22px;"></span>
<a href="#">论坛</a>
</td>
</tr>
</table><!--导航结束-->
<!--汽车开始-->
<div class="con_1">
<div class="con_2">
<table cellspacing=0 cellpadding=0 align=center class="t2">
<tr><td >
<div class=cc>
<div id="carr">
<div class="im">
<img src="images/img2.jpg" >
<p style="margin-top:2px;font-size:4px;background:#ccc;"><a href="#">全新思域颜值逆天</a></p>
</div>
<div class="content1">
<table border=0 height=90 cellspacing=0 cellpadding=0 class="t3">
<tr height=35>
<td colspan=2><a href="#" class="c1">丰田RAV4/本田CR-V 紧凑SUV谁更好</a></td>
</tr>
<tr height=35>
<td ><a href="#" >全新标致308买哪款好</a></td>
<td><a href="#" >全新标致308买哪款好</a></td>
</tr>
<tr height=35>
<td><a href="#" >全新标致308买哪款好</a></td>
<td><a href="#" >全新标致308买哪款好</a></td>
</tr>
</table>
</div>
<div class="con">
<table border=0 height=90 cellspacing=0 cellpadding=0 class="t4" width=480>
<tr height=35 >
<td ><a href="#" >全新标致308买哪款好</a></td>
<td><a href="#" >全新标致308买哪款好</a></td>
<td><a href="#" >全新标致308买哪款好</a></td>
</tr>
<tr height=35>
<td><a href="#" >全新标致308买哪款好</a></td>
<td><a href="#" >全新标致308买哪款好</a></td>
<td><a href="#" >全新标致308买哪款好</a></td>
</tr>
<tr height=35>
<td ><a href="#" >全新标致308买哪款好</a></td>
<td><a href="#" >全新标致308买哪款好</a></td>
<td><a href="#" >全新标致308买哪款好</a></td>
</tr>
<tr height=35>
<td><a href="#" >全新标致308买哪款好</a></td>
<td><a href="#" >全新标致308买哪款好</a></td>
<td><a href="#" >全新标致308买哪款好</a></td>
</tr>
<tr height=35>
<td><a href="#" >全新标致308买哪款好</a></td>
<td><a href="#" >全新标致308买哪款好</a></td>
<td><a href="#" >全新标致308买哪款好</a></td>
</tr>
</table>
<div class="foo"><a href="#" style="color:rgb(100,255,255);">广告|</a>
<span style="font-size:17px;">北现勇夺今后服务大奖&nbsp;XEV260深度试驾体验</span>
</div>
</div>
</div>
</div><!--汽车结束-->
<!--降价开始-->
<div id="jiangg" style="display:none;">
<div class="im">
<img src="images/img3.jpg" >
<p style="margin-top:2px;font-size:4px;background:#ccc;"><a href="#">全新思域颜值逆天</a></p>
</div>
<div class="content1">
<table border=0 height=90 cellspacing=0 cellpadding=0 class="t3">
<tr height=35>
<td colspan=2><a href="#" class="c1">丰田RAV4/本田CR-V 紧凑SUV谁更好</a></td>
</tr>
<tr height=35>
<td ><a href="#" >全新标致308买哪款好</a></td>
<td><a href="#" >全新标致308买哪款好</a></td>
</tr>
<tr height=35>
<td><a href="#" >全新标致308买哪款好</a></td>
<td><a href="#" >全新标致308买哪款好</a></td>
</tr>
</table>
</div>
<div class="con">
<table border=0 height=90 cellspacing=0 cellpadding=0 class="t4" width=480>
<tr height=35 >
<td ><a href="#" >全新标致308买哪款好</a></td>
<td><a href="#" >全新标致308买哪款好</a></td>
<td><a href="#" >全新标致308买哪款好</a></td>
</tr>
<tr height=35>
<td><a href="#" >全新标致308买哪款好</a></td>
<td><a href="#" >全新标致308买哪款好</a></td>
<td><a href="#" >全新标致308买哪款好</a></td>
</tr>
<tr height=35>
<td ><a href="#" >全新标致308买哪款好</a></td>
<td><a href="#" >全新标致308买哪款好</a></td>
<td><a href="#" >全新标致308买哪款好</a></td>
</tr>
<tr height=35>
<td><a href="#" >全新标致308买哪款好</a></td>
<td><a href="#" >全新标致308买哪款好</a></td>
<td><a href="#" >全新标致308买哪款好</a></td>
</tr>
<tr height=35>
<td><a href="#" >全新标致308买哪款好</a></td>
<td><a href="#" >全新标致308买哪款好</a></td>
<td><a href="#" >全新标致308买哪款好</a></td>
</tr>
</table>
</div>
<div class="foo"><a href="#" style="color:rgb(100,255,255);">广告|</a>
<span style="font-size:17px;">北现勇夺今后服务大奖&nbsp;XEV260深度试驾体验</span>
</div>
</div>
</div><!--降价结束-->
<!--二手开始-->
<div id="twoo" style="display:none;">
<div class="im">
<img src="images/img4.jpg" >
<p style="margin-top:2px;font-size:4px;background:#ccc;"><a href="#">全新思域颜值逆天</a></p>
</div>
<div class="content1">
<table border=0 height=90 cellspacing=0 cellpadding=0 class="t3">
<tr height=35>
<td colspan=2><a href="#" class="c1">丰田RAV4/本田CR-V 紧凑SUV谁更好</a></td>
</tr>
<tr height=35>
<td ><a href="#" >全新标致308买哪款好</a></td>
<td><a href="#" >全新标致308买哪款好</a></td>
</tr>
<tr height=35>
<td><a href="#" >全新标致308买哪款好</a></td>
<td><a href="#" >全新标致308买哪款好</a></td>
</tr>
</table>
</div>
<div class="con">
<table border=0 height=90 cellspacing=0 cellpadding=0 class="t4" width=480>
<tr height=35 >
<td ><a href="#" >全新标致308买哪款好</a></td>
<td><a href="#" >全新标致308买哪款好</a></td>
<td><a href="#" >全新标致308买哪款好</a></td>
</tr>
<tr height=35>
<td><a href="#" >全新标致308买哪款好</a></td>
<td><a href="#" >全新标致308买哪款好</a></td>
<td><a href="#" >全新标致308买哪款好</a></td>
</tr>
<tr height=35>
<td ><a href="#" >全新标致308买哪款好</a></td>
<td><a href="#" >全新标致308买哪款好</a></td>
<td><a href="#" >全新标致308买哪款好</a></td>
</tr>
<tr height=35>
<td><a href="#" >全新标致308买哪款好</a></td>
<td><a href="#" >全新标致308买哪款好</a></td>
<td><a href="#" >全新标致308买哪款好</a></td>
</tr>
<tr height=35>
<td><a href="#" >全新标致308买哪款好</a></td>
<td><a href="#" >全新标致308买哪款好</a></td>
<td><a href="#" >全新标致308买哪款好</a></td>
</tr>
</table>
</div>
<div class="foo"><a href="#" style="color:rgb(100,255,255);">广告|</a>
<span style="font-size:17px;">北现勇夺今后服务大奖&nbsp;XEV260深度试驾体验</span>
</div>
<!--二手车结束-->
</td></tr>
</table>
</div>
</div>
</div>
<script>
function op(t){
if(t=='car'){
document.getElementById('car2').style.display="none";
document.getElementById('car1').style.display="block";
document.getElementById('jiang2').style.display="block";
document.getElementById('two2').style.display="block";
document.getElementById('two1').style.display="none";
document.getElementById('jiang1').style.display="none";
document.getElementById('carr').style.display="block";
document.getElementById('twoo').style.display="none";
document.getElementById('jiangg').style.display="none";
}else if(t=='jiang'){
document.getElementById('car1').style.display="none";
document.getElementById('car2').style.display="block";
document.getElementById('jiang1').style.display="block";
document.getElementById('two2').style.display="block";
document.getElementById('two1').style.display="none";
document.getElementById('jiang2').style.display="none";
document.getElementById('carr').style.display="none";
document.getElementById('twoo').style.display="none";
document.getElementById('jiangg').style.display="block";
}else if(t=='two'){
document.getElementById('car1').style.display="none";
document.getElementById('car2').style.display="block";
document.getElementById('jiang2').style.display="block";
document.getElementById('two1').style.display="block";
document.getElementById('two2').style.display="none";
document.getElementById('jiang1').style.display="none";
document.getElementById('carr').style.display="none";
document.getElementById('twoo').style.display="block";
document.getElementById('jiangg').style.display="none";
}
}
</script>

16、text_onbluronfocus改变文本框的字

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
</HEAD>
<BODY>
<input type="text" id="myname" value="输入关键字" onblur="had()" onfocus="cut()">
<script type="text/javascript">
function had(){
if(document.getElementById("myname").value==""){
document.getElementById("myname").value="输入关键字";}
}
function cut(){
document.getElementById("myname").value="";
}
</script>
</BODY>
</HTML>

17、双色球的数字随机产生

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<meta charset=utf-8>
<script language="javascript">
//Math.random() 0-1之间的一个随机数
for(j=1;j<=10;j++)
{
document.write("红球:");
for(i=1;i<=6;i++)
{
var num=Math.floor(Math.random()*33+1);
document.write(num+"\t");
}
num=Math.floor(Math.random()*16+1);
document.write("蓝球:"+num+"<br>");
}
</script>

18投票

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
<html>
<head><meta charset=utf-8><title>投票</title>
<style type="text/css">
table
{
font-size:13px;
line-height:25px;
}
.t1
{
width:22px;
height:20px;
border:0px;
text-align:center;
}
</style>
</head>
<body>
<table border=0 cellspacing=0 cellpadding=0>
<tr>
<td><input type=text value=0 width=20 height=20 id="beishang_text" width=20 class=t1></td>
<td><input type=text value=0 width=20 height=20 id="chaozuo_text" width=20 class=t1></td>
<td><input type=text value=0 width=20 height=20 id="fennu_text" width=20 class=t1></td>
<td><input type=text value=0 width=20 height=20 id="gandong_text" width=20 class=t1></td>
<td><input type=text value=0 width=20 height=20 id="gaoxing_text" width=20 class=t1></td>
<td><input type=text value=0 width=20 height=20 id="wuliao_text" width=20 class=t1></td>
<td> <input type=text value=0 width=20 height=20 id="yangyan_text" width=20 class=t1></td>
</tr>
<tr valign=bottom>
<td><img src="images/xq.gif" id="beishang_img" width=20></td>
<td><img src="images/xq.gif" id="chaozuo_img" width=20></td>
<td><img src="images/xq.gif" id="fennu_img" width=20></td>
<td><img src="images/xq.gif" id="gandong_img" width=20></td>
<td><img src="images/xq.gif" id="gaoxing_img" width=20></td>
<td><img src="images/xq.gif" id="wuliao_img" width=20></td>
<td><img src="images/xq.gif" id="yangyan_img" width=20></td>
</tr>
<tr>
<td><img src="images/beishang.gif" width=20 onclick="my('beishang')"></td>
<td><img src="images/chaozuo.gif" width=20 onclick="my('chaozuo')"></td>
<td><img src="images/fennu.gif" width=20 onclick="my('fennu')"></td>
<td><img src="images/gandong.gif" width=20 onclick="my('gandong')"></td>
<td><img src="images/gaoxiao.gif" width=20 onclick="my('gaoxiao')"></td>
<td><img src="images/wuliao.gif" width=20 onclick="my('wuliao')"></td>
<td><img src="images/yangyan.gif" width=20 onclick="my('yangyan')"></td>
</tr>
</table>
<script>
function my(o){
var beishang=document.getElementById('beishang_img');
var beishang_text=document.getElementById('beishang_text').value;
if(o=='beishang'){
beishang_text++;
beishang.height=beishang_text;
document.getElementById('beishang_text').value=beishang_text;
}
var chaozuo=document.getElementById('chaozuo_img');
var chaozuo_text=document.getElementById('chaozuo_text').value;
if(o=='chaozuo'){
chaozuo_text++;
chaozuo.height=chaozuo_text;
document.getElementById('chaozuo_text').value=chaozuo_text;
}
}
</script>
</body>
</html>

19、用户名文本框背景变色_className

1
2
3
4
5
6
7
8
9
10
11
12
13
14
<meta charset=utf-8>
<style type="text/css">
.a1 /*定义名为a1的类选择符*/
{
background:#FFFF00;
border:2px solid #FF0000;
}
.a2
{
background:#FFFFFF;
border:1px solid #CCCCCC;
}
</style>
用户名:<input type=text id=username onfocus="this.className='a1'" onblur="this.className='a2'">

20、运算符

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
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<meta charset=utf-8>
<meta http-equiv="refresh" content="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
</HEAD>
<BODY>
算术运算符:+,-,*,/,++,--,%<br>
<script>
document.write("10+3="+(10+3)+"<br>");
document.write((10*3)+"<br>");
document.write("10/3="+(10/3)+"<br>");
document.write("10%3="+(10%3)+"<br>");
document.write("10%-3="+(10%-3)+"<br>");
document.write("-10%3="+(-10%3)+"<br>");
document.write("-10%-3="+(-10%-3)+"<br>");
var a=10;
document.write("b=++a="+(++a)+"<br>");
document.write("d=a++="+(a++)+"<br>");
document.write("f=--a="+(--a)+"<br>");
document.write("n=a--="+(a--)+"<br>");
</script>
<hr>
逻辑运算符:逻辑与(&&)、逻辑或(||)、逻辑非(!)
<hr>
关系运算符:(大于)>,(大于等于)>=,(小于)<,(小于等于)<=,(等于)==,(不等)!=<br>
<font>
关系运算符的值有:true、false</font><br>
<script>
a=10,b=7,c=9;
document.write("(a>b)&&(b>c)为"+((a>b)&&(b>c))+"<br>");
document.write("(a>b)||(b>c)为"+((a>b)||(b>c))+"<br>");
document.write("(a>b)&&(b<c)为"+(a>b)&&(b<c)+"<br>");
document.write("(a>b)||(b>=c)为"+(a>b)||(b>=c)+"<br>");
</script>
<hr>
位运算符:
<code>&</code><br>
<script>
document.write("(5&3)为"+(5&3)+"<br>")
</script>
<hr>
左移:<font> << </font><br>
<script>
document.write("(5<<3)为"+(5<<3)+"<br>");
</script>
<hr>
右移:<font> >> </font><br>
<script>
document.write("(5>>3)为"+(5>>3)+"<br>");
</script>
</BODY>
</HTML>