Nothing 2008-4-27 19:22
事半功倍之js
[color=#000000]第一章javascript简介
1[color=#0000cc].[/color]在地址栏输入javascript语句
Javascript:Document[color=#0000cc].[/color]write[color=#0000cc]([/color][color=#ff00ff]"显示文字"[/color][color=#0000cc])[/color]
2[color=#0000cc].[/color]将javascript嵌入 HTML文档
[color=#0000cc]<[/color][color=#0000ff]script[/color] [color=#ff0000]language[/color][color=#0000cc]=[/color]javascript[color=#0000cc]>[/color]
document[color=#0000cc].[/color][color=#ff0000]bgColor[/color][color=#0000cc]=[/color][color=#ff00ff]"blue"[/color]
[color=#0000cc]<[/color][color=#0000cc]/[/color][color=#0000ff]script[/color][color=#0000cc]>[/color]
第二章 使用变量和数组
1[color=#0000cc].[/color]声明变量
[color=#0000cc]<[/color][color=#0000ff]script[/color] [color=#ff0000]language[/color][color=#0000cc]=[/color]javascripe[color=#0000cc]>[/color]
[color=#0000ff]Var[/color] answer1[color=#0000cc],[/color]answer2[color=#0000cc],[/color]answer3[color=#0000cc],[/color]answer4[color=#0000cc];[/color]
answer1[color=#0000cc]=[/color]9[color=#0000cc];[/color]
answer2[color=#0000cc]=[/color]2[color=#0000cc].[/color]5
answer3[color=#0000cc]=[/color][color=#ff00ff]"Milkey May"[/color]
answer4[color=#0000cc]=[/color]true
[color=#0000cc]<[/color][color=#0000cc]/[/color][color=#0000ff]script[/color][color=#0000cc]>[/color]
2[color=#0000cc].[/color]使用整数
[color=#0000cc]<[/color][color=#0000ff]script[/color] [color=#ff0000]language[/color][color=#0000cc]=[/color]javascript[color=#0000cc]>[/color]
[color=#0000ff]var[/color] decimalNum[color=#0000cc],[/color]hexadecimalNum[color=#0000cc],[/color]octalNum
decimalNum[color=#0000cc]=[/color]24
hexadecimalNum[color=#0000cc]=[/color]0x24
octalNum[color=#0000cc]=[/color]024
document[color=#0000cc].[/color]write[color=#0000cc]([/color][color=#ff00ff]"显示十进制数:"[/color][color=#0000cc]+[/color] decimalNum[color=#0000cc]+[/color][color=#ff00ff]"<br>"[/color][color=#0000cc])[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color][color=#ff00ff]"显示十六进制数:"[/color][color=#0000cc]+[/color] hexadecimalNum [color=#0000cc]+[/color][color=#ff00ff]"<br>"[/color][color=#0000cc])[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color][color=#ff00ff]"显示八进制数:"[/color][color=#0000cc]+[/color] octalNum [color=#0000cc]+[/color][color=#ff00ff]"<br>"[/color][color=#0000cc])[/color]
[color=#0000cc]<[/color][color=#0000cc]/[/color][color=#0000ff]script[/color][color=#0000cc]>[/color]
3[color=#0000cc].[/color]使用浮点数
[color=#0000cc]<[/color][color=#0000ff]script[/color] [color=#ff0000]language[/color][color=#0000cc]=[/color]javascript[color=#0000cc]>[/color]
[color=#0000ff]var[/color] num1[color=#0000cc],[/color]num2[color=#0000cc],[/color]num3[color=#0000cc],[/color]num4
num1[color=#0000cc]=[/color]1234567890000[color=#0000cc].[/color]0
num2[color=#0000cc]=[/color]5[color=#0000cc].[/color]14e23
num3[color=#0000cc]=[/color]0[color=#0000cc].[/color]0000123456
num4[color=#0000cc]=[/color]6[color=#0000cc].[/color]0254e3-4
document[color=#0000cc].[/color]write[color=#0000cc]([/color][color=#ff00ff]"浮点数1:"[/color][color=#0000cc]+[/color]num1[color=#0000cc]+[/color][color=#ff00ff]"<br>"[/color][color=#0000cc])[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color][color=#ff00ff]"浮点数2:"[/color][color=#0000cc]+[/color]num2[color=#0000cc]+[/color][color=#ff00ff]"<br>"[/color][color=#0000cc])[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color][color=#ff00ff]"浮点数3:"[/color][color=#0000cc]+[/color]num3[color=#0000cc]+[/color][color=#ff00ff]"<br>"[/color][color=#0000cc])[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color][color=#ff00ff]"浮点数4:"[/color][color=#0000cc]+[/color]num4[color=#0000cc]+[/color][color=#ff00ff]"<br>"[/color][color=#0000cc])[/color]
[color=#0000cc]<[/color][color=#0000cc]/[/color][color=#0000ff]script[/color][color=#0000cc]>[/color]
4[color=#0000cc].[/color]使用布尔值
[color=#0000cc]<[/color][color=#0000ff]script[/color] [color=#ff0000]language[/color][color=#0000cc]=[/color]javascript[color=#0000cc]>[/color]
[color=#0000ff]var[/color] answer1[color=#0000cc],[/color]answer2
answer1[color=#0000cc]=[/color]true
answer2[color=#0000cc]=[/color]false
document[color=#0000cc].[/color]write[color=#0000cc]([/color][color=#ff00ff]"显示布尔1:"[/color][color=#0000cc]+[/color]answer1[color=#0000cc]+[/color][color=#ff00ff]"<br>"[/color][color=#0000cc])[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color][color=#ff00ff]"显示布尔2:"[/color][color=#0000cc]+[/color]answer2[color=#0000cc]+[/color][color=#ff00ff]"<br>"[/color][color=#0000cc])[/color]
[color=#0000cc]<[/color][color=#0000cc]/[/color][color=#0000ff]script[/color][color=#0000cc]>[/color]
5[color=#0000cc].[/color]使用字符串
[color=#0000cc]<[/color][color=#0000ff]script[/color] [color=#ff0000]language[/color][color=#0000cc]=[/color]javascript[color=#0000cc]>[/color]
[color=#0000ff]var[/color] str1[color=#0000cc],[/color]str2
str1[color=#0000cc]=[/color][color=#ff00ff]"fdsgdg dsfdsf china"[/color]
str2[color=#0000cc]=[/color][color=#ff00ff]"武汉市广播电视大学"[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color][color=#ff00ff]"显示字符串1:"[/color][color=#0000cc]+[/color]str1[color=#0000cc]+[/color][color=#ff00ff]"<br>"[/color][color=#0000cc])[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color][color=#ff00ff]"显示字符串2:"[/color][color=#0000cc]+[/color]str2[color=#0000cc]+[/color][color=#ff00ff]"<br>"[/color][color=#0000cc])[/color]
[color=#0000cc]<[/color][color=#0000cc]/[/color][color=#0000ff]script[/color][color=#0000cc]>[/color]
6[color=#0000cc].[/color]确定变量类型
[color=#0000cc]<[/color][color=#0000ff]script[/color][color=#0000cc]>[/color]
[color=#0000ff]var[/color] answer1[color=#0000cc],[/color]answer2[color=#0000cc],[/color]answer3[color=#0000cc],[/color]answer4
answer1[color=#0000cc]=[/color]9
answer2[color=#0000cc]=[/color]2[color=#0000cc].[/color]5
answer3[color=#0000cc]=[/color][color=#ff00ff]"milky may"[/color]
answer4[color=#0000cc]=[/color]true
document[color=#0000cc].[/color]write[color=#0000cc]([/color][color=#ff00ff]"变量1的类型是:"[/color][color=#0000cc]+[/color]typeof answer1 [color=#0000cc]+[/color][color=#ff00ff]"<br>"[/color][color=#0000cc])[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color][color=#ff00ff]"变量2的类型是:"[/color][color=#0000cc]+[/color]typeof answer2 [color=#0000cc]+[/color][color=#ff00ff]"<br>"[/color][color=#0000cc])[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color][color=#ff00ff]"变量3的类型是:"[/color][color=#0000cc]+[/color]typeof answer3 [color=#0000cc]+[/color][color=#ff00ff]"<br>"[/color][color=#0000cc])[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color][color=#ff00ff]"变量4的类型是:"[/color][color=#0000cc]+[/color]typeof answer4 [color=#0000cc]+[/color][color=#ff00ff]"<br>"[/color][color=#0000cc])[/color]
[color=#0000cc]<[/color][color=#0000cc]/[/color][color=#0000ff]script[/color][color=#0000cc]>[/color]
7[color=#0000cc].[/color]将字符串转换成数字
[color=#0000cc]<[/color][color=#0000ff]script[/color][color=#0000cc]>[/color]
[color=#0000ff]var[/color] str1[color=#0000cc]=[/color][color=#ff00ff]"31 days in january"[/color]
[color=#0000ff]var[/color] int1[color=#0000cc]=[/color]parseInt[color=#0000cc]([/color]str1[color=#0000cc])[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color][color=#ff00ff]"str1的数据类型是 :"[/color][color=#0000cc]+[/color]typeof str1[color=#0000cc]+[/color][color=#ff00ff]"<br>"[/color][color=#0000cc])[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color][color=#ff00ff]"int1的数据类型是 :"[/color][color=#0000cc]+[/color]typeof int1[color=#0000cc]+[/color][color=#ff00ff]"<br>"[/color][color=#0000cc])[/color]
[color=#0000cc]<[/color][color=#0000cc]/[/color][color=#0000ff]script[/color][color=#0000cc]>[/color]
8[color=#0000cc].[/color]将数字转换成字符串
[color=#0000cc]<[/color][color=#0000ff]script[/color][color=#0000cc]>[/color]
[color=#0000ff]var[/color] int1[color=#0000cc]=[/color]256
[color=#0000ff]var[/color] str1[color=#0000cc]=[/color][color=#ff00ff]""[/color][color=#0000cc]+[/color]int1
document[color=#0000cc].[/color]write[color=#0000cc]([/color][color=#ff00ff]"str1的数据类型是 :"[/color][color=#0000cc]+[/color]typeof str1[color=#0000cc]+[/color][color=#ff00ff]"<br>"[/color][color=#0000cc])[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color][color=#ff00ff]"int1的数据类型是 :"[/color][color=#0000cc]+[/color]typeof int1[color=#0000cc]+[/color][color=#ff00ff]"<br>"[/color][color=#0000cc])[/color]
[color=#0000cc]<[/color][color=#0000cc]/[/color][color=#0000ff]script[/color][color=#0000cc]>[/color]
9[color=#0000cc].[/color]声明数组
[color=#0000cc]<[/color][color=#0000ff]script[/color][color=#0000cc]>[/color]
array[color=#0000cc]=[/color]new Array[color=#0000cc]([/color]5[color=#0000cc])[/color]
array[color=#0000cc][[/color]0[color=#0000cc]][/color][color=#0000cc]=[/color]1
array[color=#0000cc][[/color]1[color=#0000cc]][/color][color=#0000cc]=[/color]3
array[color=#0000cc][[/color]2[color=#0000cc]][/color][color=#0000cc]=[/color]5
array[color=#0000cc][[/color]3[color=#0000cc]][/color][color=#0000cc]=[/color]7
array[color=#0000cc][[/color]4[color=#0000cc]][/color][color=#0000cc]=[/color]11
document[color=#0000cc].[/color]write[color=#0000cc]([/color][color=#ff00ff]"数组是:"[/color][color=#0000cc]+[/color]array[color=#0000cc][[/color]0[color=#0000cc]][/color][color=#0000cc]+[/color][color=#ff00ff]" "[/color][color=#0000cc]+[/color]array[color=#0000cc][[/color]1[color=#0000cc]][/color][color=#0000cc]+[/color][color=#ff00ff]" "[/color][color=#0000cc]+[/color]array[color=#0000cc][[/color]2[color=#0000cc]][/color][color=#0000cc]+[/color][color=#ff00ff]" "[/color][color=#0000cc]+[/color]array[color=#0000cc][[/color]3[color=#0000cc]][/color][color=#0000cc]+[/color][color=#ff00ff]" "[/color][color=#0000cc]+[/color]array[color=#0000cc][[/color]4[color=#0000cc]][/color][color=#0000cc])[/color]
[color=#0000cc]<[/color][color=#0000cc]/[/color][color=#0000ff]script[/color][color=#0000cc]>[/color]
10[color=#0000cc].[/color]确定数组元素的个数
[color=#0000cc]<[/color][color=#0000ff]script[/color][color=#0000cc]>[/color]
array[color=#0000cc]=[/color]new Array[color=#0000cc]([/color]5[color=#0000cc])[/color]
array[color=#0000cc][[/color]0[color=#0000cc]][/color][color=#0000cc]=[/color]1
array[color=#0000cc][[/color]1[color=#0000cc]][/color][color=#0000cc]=[/color]3
array[color=#0000cc][[/color]2[color=#0000cc]][/color][color=#0000cc]=[/color]5
array[color=#0000cc][[/color]3[color=#0000cc]][/color][color=#0000cc]=[/color]7
array[color=#0000cc][[/color]4[color=#0000cc]][/color][color=#0000cc]=[/color]11
document[color=#0000cc].[/color]write[color=#0000cc]([/color][color=#ff00ff]"数组是:"[/color][color=#0000cc]+[/color]array[color=#0000cc][[/color]0[color=#0000cc]][/color][color=#0000cc]+[/color][color=#ff00ff]" "[/color][color=#0000cc]+[/color]array[color=#0000cc][[/color]1[color=#0000cc]][/color][color=#0000cc]+[/color][color=#ff00ff]" "[/color][color=#0000cc]+[/color]array[color=#0000cc][[/color]2[color=#0000cc]][/color][color=#0000cc]+[/color][color=#ff00ff]" "[/color][color=#0000cc]+[/color]array[color=#0000cc][[/color]3[color=#0000cc]][/color][color=#0000cc]+[/color][color=#ff00ff]" "[/color][color=#0000cc]+[/color]array[color=#0000cc][[/color]4[color=#0000cc]][/color][color=#0000cc]+[/color][color=#ff00ff]"<br>"[/color][color=#0000cc])[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color][color=#ff00ff]"数组的元素个数是"[/color][color=#0000cc]+[/color]array[color=#0000cc].[/color]length[color=#0000cc])[/color]
[color=#0000cc]<[/color][color=#0000cc]/[/color][color=#0000ff]script[/color][color=#0000cc]>[/color]
11[color=#0000cc].[/color]将数组转换为字符串
[color=#0000cc]<[/color][color=#0000ff]script[/color][color=#0000cc]>[/color]
array[color=#0000cc]=[/color]new Array[color=#0000cc]([/color][color=#0000cc])[/color]
array[color=#0000cc][[/color]0[color=#0000cc]][/color][color=#0000cc]=[/color][color=#ff00ff]"dark"[/color]
array[color=#0000cc][[/color]1[color=#0000cc]][/color][color=#0000cc]=[/color][color=#ff00ff]"apple"[/color]
array[color=#0000cc][[/color]2[color=#0000cc]][/color][color=#0000cc]=[/color][color=#ff00ff]"nebula"[/color]
array[color=#0000cc][[/color]3[color=#0000cc]][/color][color=#0000cc]=[/color][color=#ff00ff]"water"[/color]
str1[color=#0000cc]=[/color]array[color=#0000cc].[/color]join[color=#0000cc]([/color][color=#0000cc])[/color]
str2[color=#0000cc]=[/color]array[color=#0000cc].[/color]join[color=#0000cc]([/color][color=#ff00ff]" "[/color][color=#0000cc])[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color]str1[color=#0000cc]+[/color][color=#ff00ff]"<br>"[/color][color=#0000cc])[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color]str2[color=#0000cc])[/color]
[color=#0000cc]<[/color][color=#0000cc]/[/color][color=#0000ff]script[/color][color=#0000cc]>[/color]
12[color=#0000cc].[/color]对数组排序
[color=#0000cc]<[/color][color=#0000ff]script[/color][color=#0000cc]>[/color]
array[color=#0000cc]=[/color]new Array[color=#0000cc]([/color][color=#0000cc])[/color]
array[color=#0000cc][[/color]0[color=#0000cc]][/color][color=#0000cc]=[/color][color=#ff00ff]"dark"[/color]
array[color=#0000cc][[/color]1[color=#0000cc]][/color][color=#0000cc]=[/color][color=#ff00ff]"apple"[/color]
array[color=#0000cc][[/color]2[color=#0000cc]][/color][color=#0000cc]=[/color][color=#ff00ff]"nebula"[/color]
array[color=#0000cc][[/color]3[color=#0000cc]][/color][color=#0000cc]=[/color][color=#ff00ff]"water"[/color]
str1[color=#0000cc]=[/color]array[color=#0000cc].[/color]sort[color=#0000cc]([/color][color=#0000cc])[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color]str1[color=#0000cc]+[/color][color=#ff00ff]"<br>"[/color][color=#0000cc])[/color]
[color=#0000cc]<[/color][color=#0000cc]/[/color][color=#0000ff]script[/color][color=#0000cc]>[/color]
第三章 创建表达式
1[color=#0000cc].[/color]使用算术运算符
[color=#0000cc]<[/color][color=#0000ff]script[/color][color=#0000cc]>[/color]
var1[color=#0000cc]=[/color]12
var2[color=#0000cc]=[/color]10
varadd[color=#0000cc]=[/color]var1[color=#0000cc]+[/color]var2
varsub[color=#0000cc]=[/color]var1-var2
varmult[color=#0000cc]=[/color]var1[color=#0000cc]*[/color]var2
vardiv[color=#0000cc]=[/color]var1[color=#0000cc]/[/color]var2
varmod[color=#0000cc]=[/color]var1[color=#0000cc]%[/color]var2
document[color=#0000cc].[/color]write[color=#0000cc]([/color][color=#ff00ff]"数据1是:"[/color][color=#0000cc]+[/color]var1[color=#0000cc]+[/color][color=#ff00ff]"<br>"[/color][color=#0000cc])[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color][color=#ff00ff]"数据2是:"[/color][color=#0000cc]+[/color]var2[color=#0000cc]+[/color][color=#ff00ff]"<br>"[/color][color=#0000cc])[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color][color=#ff00ff]"数据相加是:"[/color][color=#0000cc]+[/color]varadd[color=#0000cc]+[/color][color=#ff00ff]"<br>"[/color][color=#0000cc])[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color][color=#ff00ff]"数据相减是:"[/color][color=#0000cc]+[/color]varsub[color=#0000cc]+[/color][color=#ff00ff]"<br>"[/color][color=#0000cc])[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color][color=#ff00ff]"数据相乘是:"[/color][color=#0000cc]+[/color]varmult[color=#0000cc]+[/color][color=#ff00ff]"<br>"[/color][color=#0000cc])[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color][color=#ff00ff]"数据相除是:"[/color][color=#0000cc]+[/color]vardiv[color=#0000cc]+[/color][color=#ff00ff]"<br>"[/color][color=#0000cc])[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color][color=#ff00ff]"数据相除取余数是:"[/color][color=#0000cc]+[/color]varmod[color=#0000cc]+[/color][color=#ff00ff]"<br>"[/color][color=#0000cc])[/color]
[color=#0000cc]<[/color][color=#0000cc]/[/color][color=#0000ff]script[/color][color=#0000cc]>[/color]
2[color=#0000cc].[/color]递增变量和递减变量
[color=#0000cc]<[/color][color=#0000ff]script[/color][color=#0000cc]>[/color]
days[color=#0000cc]=[/color]1
document[color=#0000cc].[/color]write[color=#0000cc]([/color][color=#ff00ff]"输出变量"[/color][color=#0000cc]+[/color]days[color=#0000cc]+[/color][color=#ff00ff]"<br>"[/color][color=#0000cc])[/color]
days[color=#0000cc]+[/color][color=#0000cc]+[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color][color=#ff00ff]"递增后变量变为:"[/color][color=#0000cc]+[/color]days[color=#0000cc])[/color]
[color=#0000cc]<[/color][color=#0000cc]/[/color][color=#0000ff]script[/color][color=#0000cc]>[/color]
3[color=#0000cc].[/color]创建比较表达式
[color=#0000cc]<[/color][color=#0000ff]script[/color][color=#0000cc]>[/color]
daysofmonth[color=#0000cc]=[/color]28
if[color=#0000cc]([/color]daysofmonth[color=#0000cc]=[/color][color=#0000cc]=[/color]28[color=#0000cc])[/color]
month[color=#0000cc]=[/color][color=#ff00ff]"february"[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color][color=#ff00ff]"days of month:"[/color][color=#0000cc]+[/color]daysofmonth[color=#0000cc]+[/color][color=#ff00ff]"<br>"[/color][color=#0000cc])[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color][color=#ff00ff]"month:"[/color][color=#0000cc]+[/color]month[color=#0000cc])[/color]
[color=#0000cc]<[/color][color=#0000cc]/[/color][color=#0000ff]script[/color][color=#0000cc]>[/color]
4[color=#0000cc].[/color]创建逻辑表达式
[color=#0000cc]<[/color][color=#0000ff]script[/color][color=#0000cc]>[/color]
dayofmonth[color=#0000cc]=[/color]28
if[color=#0000cc]([/color]dayofmonth[color=#0000cc]=[/color][color=#0000cc]=[/color]28 [color=#0000cc]|[/color][color=#0000cc]|[/color] dayofmonth[color=#0000cc]=[/color][color=#0000cc]=[/color]29[color=#0000cc])[/color]
month[color=#0000cc]=[/color][color=#ff00ff]"february"[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color][color=#ff00ff]"days of month:"[/color][color=#0000cc]+[/color]dayofmonth[color=#0000cc]+[/color][color=#ff00ff]"<br>"[/color][color=#0000cc])[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color][color=#ff00ff]"month:"[/color][color=#0000cc]+[/color]month[color=#0000cc])[/color]
[color=#0000cc]<[/color][color=#0000cc]/[/color][color=#0000ff]script[/color][color=#0000cc]>[/color]
5[color=#0000cc].[/color]使用条件运算符
[color=#0000cc]<[/color][color=#0000ff]script[/color] [color=#ff0000]language[/color][color=#0000cc]=[/color][color=#ff00ff]"javascript"[/color][color=#0000cc]>[/color]
stomach[color=#0000cc]=[/color][color=#ff00ff]"hungry"[/color][color=#0000cc];[/color]
time[color=#0000cc]=[/color][color=#ff00ff]"5:00"[/color][color=#0000cc];[/color]
[color=#0000cc]([/color]stomach[color=#0000cc]=[/color][color=#0000cc]=[/color][color=#ff00ff]"hungry"[/color][color=#0000cc]&[/color][color=#0000cc]&[/color]time[color=#0000cc]=[/color][color=#0000cc]=[/color][color=#ff00ff]"5:00"[/color][color=#0000cc])[/color] ? eat [color=#0000cc]=[/color] [color=#ff00ff]"dinner"[/color][color=#ff00ff]:[/color]eat[color=#0000cc]=[/color][color=#ff00ff]"a snack"[/color][color=#0000cc];[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color][color=#ff00ff]"输出结果"[/color][color=#0000cc]+[/color]eat[color=#0000cc])[/color][color=#0000cc];[/color]
[color=#0000cc]<[/color][color=#0000cc]/[/color][color=#0000ff]script[/color][color=#0000cc]>[/color]
6[color=#0000cc].[/color]识别数字
[color=#0000cc]<[/color][color=#0000ff]script[/color][color=#0000cc]>[/color]
var1[color=#0000cc]=[/color]24[color=#0000cc];[/color]
[color=#0000cc]([/color]isNaN[color=#0000cc]([/color]var1[color=#0000cc])[/color][color=#0000cc])[/color][color=#0000cc]?[/color]document[color=#0000cc].[/color]write[color=#0000cc]([/color][color=#ff00ff]"变量var1"[/color][color=#0000cc]+[/color]var1[color=#0000cc]+[/color][color=#ff00ff]"不是数字"[/color][color=#0000cc])[/color][color=#0000cc]:[/color]Document[color=#0000cc].[/color]write[color=#0000cc]([/color][color=#ff00ff]"变量var1"[/color][color=#0000cc]+[/color]var1[color=#0000cc]+[/color][color=#ff00ff]"是数字"[/color][color=#0000cc])[/color]
[color=#0000cc]<[/color][color=#0000cc]/[/color][color=#0000ff]script[/color][color=#0000cc]>[/color]
第四章 控制程序流程
1[color=#0000cc].[/color]使用IF –Else语句
[color=#0000cc]<[/color][color=#0000ff]script[/color][color=#0000cc]>[/color]
month[color=#0000cc]=[/color][color=#ff00ff]"december"[/color]
date[color=#0000cc]=[/color]25
if[color=#0000cc]([/color]month[color=#0000cc]=[/color][color=#0000cc]=[/color][color=#ff00ff]"december"[/color] [color=#0000cc]&[/color][color=#0000cc]&[/color] date[color=#0000cc]=[/color][color=#0000cc]=[/color]25[color=#0000cc])[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color][color=#ff00ff]"今天是圣诞节,商店关门"[/color][color=#0000cc])[/color]
else
document[color=#0000cc].[/color]write[color=#0000cc]([/color][color=#ff00ff]"欢迎,您来商店购物"[/color][color=#0000cc])[/color]
[color=#0000cc]<[/color][color=#0000cc]/[/color][color=#0000ff]script[/color][color=#0000cc]>[/color]
2[color=#0000cc].[/color]使用for 循环
[color=#0000cc]<[/color][color=#0000ff]script[/color][color=#0000cc]>[/color]
[color=#ff0000]for[/color] [color=#0000cc]([/color]count[color=#0000cc]=[/color]1[color=#0000cc];[/color]count[color=#0000cc]<[/color][color=#0000cc]=[/color]10[color=#0000cc];[/color]count[color=#0000cc]+[/color][color=#0000cc]+[/color][color=#0000cc])[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color][color=#ff00ff]"输出第"[/color][color=#0000cc]+[/color]count[color=#0000cc]+[/color][color=#ff00ff]"句"[/color][color=#0000cc]+[/color][color=#ff00ff]"<br>"[/color][color=#0000cc])[/color]
[color=#0000cc]<[/color][color=#0000cc]/[/color][color=#0000ff]script[/color][color=#0000cc]>[/color] [/color]
Nothing 2008-4-27 19:23
[color=#000000]3[color=#0000cc].[/color]使用while循环
[color=#0000cc]<[/color][color=#0000ff]script[/color][color=#0000cc]>[/color]
count[color=#0000cc]=[/color]1
while[color=#0000cc]([/color]count[color=#0000cc]<[/color][color=#0000cc]=[/color]15[color=#0000cc])[/color][color=#0000cc]{[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color][color=#ff00ff]"输出第"[/color][color=#0000cc]+[/color]count[color=#0000cc]+[/color][color=#ff00ff]"句"[/color] [color=#0000cc]+[/color][color=#ff00ff]"<br>"[/color][color=#0000cc])[/color]
count[color=#0000cc]+[/color][color=#0000cc]+[/color][color=#0000cc]}[/color]
[color=#0000cc]<[/color][color=#0000cc]/[/color][color=#0000ff]script[/color][color=#0000cc]>[/color]
4[color=#0000cc].[/color]中断循环
[color=#0000cc]<[/color][color=#0000ff]script[/color][color=#0000cc]>[/color]
count[color=#0000cc]=[/color]1
while[color=#0000cc]([/color]count[color=#0000cc]<[/color][color=#0000cc]=[/color]15[color=#0000cc])[/color][color=#0000cc]{[/color]
count[color=#0000cc]+[/color][color=#0000cc]+[/color]
if[color=#0000cc]([/color]count[color=#0000cc]=[/color][color=#0000cc]=[/color]8[color=#0000cc])[/color]
break[color=#0000cc];[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color][color=#ff00ff]"输出第"[/color][color=#0000cc]+[/color]count[color=#0000cc]+[/color][color=#ff00ff]"句"[/color][color=#0000cc]+[/color][color=#ff00ff]"<br>"[/color][color=#0000cc])[/color][color=#0000cc]}[/color]
[color=#0000cc]<[/color][color=#0000cc]/[/color][color=#0000ff]script[/color][color=#0000cc]>[/color]
5[color=#0000cc].[/color]继续循环
[color=#0000cc]<[/color][color=#0000ff]script[/color][color=#0000cc]>[/color]
count[color=#0000cc]=[/color]1
while[color=#0000cc]([/color]count[color=#0000cc]<[/color][color=#0000cc]=[/color]15[color=#0000cc])[/color][color=#0000cc]{[/color]
count[color=#0000cc]+[/color][color=#0000cc]+[/color]
if[color=#0000cc]([/color]count[color=#0000cc]=[/color][color=#0000cc]=[/color]8[color=#0000cc])[/color]
continue[color=#0000cc];[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color][color=#ff00ff]"输出第"[/color][color=#0000cc]+[/color]count[color=#0000cc]+[/color][color=#ff00ff]"句"[/color][color=#0000cc]+[/color][color=#ff00ff]"<br>"[/color][color=#0000cc])[/color][color=#0000cc]}[/color]
[color=#0000cc]<[/color][color=#0000cc]/[/color][color=#0000ff]script[/color][color=#0000cc]>[/color]
6[color=#0000cc].[/color]使用javascript定时器
[color=#0000cc]<[/color][color=#0000ff]script[/color][color=#0000cc]>[/color]
function rabbit[color=#0000cc]([/color][color=#0000cc])[/color]
[color=#0000cc]{[/color]document[color=#0000cc].[/color]write[color=#0000cc]([/color][color=#ff00ff]"输出语句"[/color][color=#0000cc])[/color]
[color=#0000cc]}[/color]
[color=#0000cc]<[/color][color=#0000cc]/[/color][color=#0000ff]script[/color][color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000ff]body[/color] [color=#ff0000]onload[/color][color=#0000cc]=[/color]window[color=#0000cc].[/color]setTimeout[color=#0000cc]([/color]rabbit[color=#0000cc]([/color][color=#0000cc])[/color][color=#0000cc],[/color]5000[color=#0000cc])[/color][color=#0000cc]>[/color]
7[color=#0000cc].[/color]设置定期间隔
[color=#0000cc]<[/color][color=#0000ff]script[/color][color=#0000cc]>[/color]
window[color=#0000cc].[/color]setInterval[color=#0000cc]([/color][color=#ff00ff]"document.form1.text2.value=document.form1.text1.value"[/color][color=#0000cc],[/color]3000[color=#0000cc])[/color]
[color=#0000cc]<[/color][color=#0000cc]/[/color][color=#0000ff]script[/color][color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000ff]form[/color] [color=#ff0000]name[/color][color=#0000cc]=[/color]form1[color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000ff]input[/color] [color=#ff0000]type[/color][color=#0000cc]=[/color][color=#ff0000]text[/color] [color=#ff0000]name[/color][color=#0000cc]=[/color]text1[color=#0000cc]>[/color][color=#0000cc]<[/color][color=#0000ff]br[/color][color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000ff]input[/color] [color=#ff0000]type[/color][color=#0000cc]=[/color][color=#ff0000]text[/color] [color=#ff0000]name[/color][color=#0000cc]=[/color]text2[color=#0000cc]>[/color][color=#0000cc]<[/color][color=#0000ff]br[/color][color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000cc]/[/color][color=#0000ff]form[/color][color=#0000cc]>[/color]
8[color=#0000cc].[/color]清除超时和间隔
[color=#0000cc]<[/color][color=#0000ff]script[/color][color=#0000cc]>[/color]
stop[color=#0000cc]=[/color]window[color=#0000cc].[/color]setInterval[color=#0000cc]([/color][color=#ff00ff]"document.form1.text2.value=document.form1.text1.value"[/color][color=#0000cc],[/color]300[color=#0000cc])[/color]
[color=#0000cc]<[/color][color=#0000cc]/[/color][color=#0000ff]script[/color][color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000ff]form[/color] [color=#ff0000]name[/color][color=#0000cc]=[/color]form1[color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000ff]input[/color] [color=#ff0000]type[/color][color=#0000cc]=[/color][color=#ff0000]text[/color] [color=#ff0000]name[/color][color=#0000cc]=[/color]text1[color=#0000cc]>[/color][color=#0000cc]<[/color][color=#0000ff]br[/color][color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000ff]input[/color] [color=#ff0000]type[/color][color=#0000cc]=[/color][color=#ff0000]text[/color] [color=#ff0000]name[/color][color=#0000cc]=[/color]text2[color=#0000cc]>[/color][color=#0000cc]<[/color][color=#0000ff]br[/color][color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000ff]input[/color] [color=#ff0000]type[/color][color=#0000cc]=[/color][color=#0000ff]button[/color] [color=#ff0000]name[/color][color=#0000cc]=[/color]button1 [color=#ff0000]value[/color][color=#0000cc]=[/color][color=#ff00ff]" 清除超时和间隔"[/color] [color=#ff0000]onclick[/color][color=#0000cc]=[/color]clearInterval[color=#0000cc]([/color]stop[color=#0000cc])[/color][color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000cc]/[/color][color=#0000ff]form[/color][color=#0000cc]>[/color]
第五章 使用函数
1[color=#0000cc].[/color]声明函数
[color=#0000cc]<[/color][color=#0000ff]script[/color][color=#0000cc]>[/color]
function quote[color=#0000cc]([/color][color=#0000cc])[/color]
[color=#0000cc]{[/color] document[color=#0000cc].[/color]write[color=#0000cc]([/color][color=#ff00ff]"输出语句"[/color][color=#0000cc])[/color]
[color=#0000cc]}[/color]
[color=#0000cc]<[/color][color=#0000cc]/[/color][color=#0000ff]script[/color][color=#0000cc]>[/color]
2[color=#0000cc].[/color]调用函数
[color=#0000cc]<[/color][color=#0000ff]script[/color][color=#0000cc]>[/color]
function quote[color=#0000cc]([/color][color=#0000cc])[/color]
[color=#0000cc]{[/color] document[color=#0000cc].[/color]write[color=#0000cc]([/color][color=#ff00ff]"输出语句"[/color][color=#0000cc])[/color]
[color=#0000cc]}[/color]
quote[color=#0000cc]([/color][color=#0000cc])[/color]
[color=#0000cc]<[/color][color=#0000cc]/[/color][color=#0000ff]script[/color][color=#0000cc]>[/color]
3[color=#0000cc].[/color]了解全局变量和局部变量
任何不用 var关键字声明的变量都是全局变量[color=#0000cc],[/color]任何在函数外声明的变量都是全局变量
4[color=#0000cc].[/color]将参数传送给函数
[color=#0000cc]<[/color][color=#0000ff]script[/color][color=#0000cc]>[/color]
function f[color=#0000cc]([/color]item[color=#0000cc])[/color]
[color=#0000cc]{[/color]document[color=#0000cc].[/color]write[color=#0000cc]([/color][color=#ff00ff]"输出参数"[/color][color=#0000cc]+[/color]item[color=#0000cc]+[/color][color=#ff00ff]"<br>"[/color][color=#0000cc])[/color]
[color=#0000cc]}[/color]
f[color=#0000cc]([/color][color=#ff00ff]"fgdfgd"[/color][color=#0000cc])[/color]
f[color=#0000cc]([/color][color=#ff00ff]"参数二"[/color][color=#0000cc])[/color]
[color=#0000cc]<[/color][color=#0000cc]/[/color][color=#0000ff]script[/color][color=#0000cc]>[/color]
5[color=#0000cc].[/color]从函数返回值
[color=#0000cc]<[/color][color=#0000ff]script[/color][color=#0000cc]>[/color]
function average[color=#0000cc]([/color]var1[color=#0000cc],[/color]var2[color=#0000cc],[/color]var3[color=#0000cc])[/color]
[color=#0000cc]{[/color]ave[color=#0000cc]=[/color][color=#0000cc]([/color]var1[color=#0000cc]+[/color]var2[color=#0000cc]+[/color]var3[color=#0000cc])[/color][color=#0000cc]/[/color]3[color=#0000cc];[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color][color=#ff00ff]"输出结果"[/color][color=#0000cc])[/color][color=#0000cc];[/color]
return ave[color=#0000cc];[/color]
[color=#0000cc]}[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color]average[color=#0000cc]([/color]34[color=#0000cc],[/color]56[color=#0000cc],[/color]78[color=#0000cc])[/color][color=#0000cc])[/color]
[color=#0000cc]<[/color][color=#0000cc]/[/color][color=#0000ff]script[/color][color=#0000cc]>[/color]
6[color=#0000cc].[/color]通过HTML链接调用函数
[color=#0000cc]<[/color][color=#0000ff]script[/color][color=#0000cc]>[/color]
function quote[color=#0000cc]([/color][color=#0000cc])[/color][color=#0000cc]{[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color][color=#ff00ff]" 输出字符串"[/color][color=#0000cc])[/color]
[color=#0000cc]}[/color]
[color=#0000cc]<[/color][color=#0000cc]/[/color][color=#0000ff]script[/color][color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000ff]a[/color] [color=#ff0000]href[/color][color=#0000cc]=[/color]javascript:quote[color=#0000cc]([/color][color=#0000cc])[/color][color=#0000cc]>[/color]通过HTML链接调用函数[color=#0000cc]<[/color][color=#0000cc]/[/color][color=#0000ff]a[/color][color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000ff]a[/color] [color=#ff0000]href[/color][color=#0000cc]=[/color]javascript:Document[color=#0000cc].[/color]write[color=#0000cc]([/color][color=#ff00ff]"输出字符"[/color][color=#0000cc])[/color][color=#0000cc]>[/color] 通过HTML链接调用函数[color=#0000cc],[/color]直接写javascript语句[color=#0000cc]<[/color][color=#0000cc]/[/color][color=#0000ff]a[/color][color=#0000cc]>[/color]
第六章 处理事件
1[color=#0000cc].[/color]检查鼠标单击
[color=#0000cc]<[/color][color=#0000ff]form[/color] [color=#ff0000]name[/color][color=#0000cc]=[/color]form1[color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000ff]input[/color] [color=#ff0000]type[/color][color=#0000cc]=[/color][color=#0000ff]button[/color] [color=#ff0000]name[/color][color=#0000cc]=[/color]button1 [color=#ff0000]value[/color][color=#0000cc]=[/color]hello [color=#ff0000]onclick[/color][color=#0000cc]=[/color]document[color=#0000cc].[/color]form1[color=#0000cc].[/color]button1[color=#0000cc].[/color][color=#ff0000]value[/color][color=#0000cc]=[/color][color=#ff00ff]'there'[/color][color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000cc]/[/color][color=#0000ff]form[/color][color=#0000cc]>[/color]
2[color=#0000cc].[/color]检测双击
[color=#0000cc]<[/color][color=#0000ff]form[/color] [color=#ff0000]name[/color][color=#0000cc]=[/color]form1[color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000ff]input[/color] [color=#ff0000]type[/color][color=#0000cc]=[/color][color=#0000ff]button[/color] [color=#ff0000]name[/color][color=#0000cc]=[/color]button1 [color=#ff0000]value[/color][color=#0000cc]=[/color]hello [color=#ff0000]onclick[/color][color=#0000cc]=[/color]document[color=#0000cc].[/color]form1[color=#0000cc].[/color]button1[color=#0000cc].[/color][color=#ff0000]value[/color][color=#0000cc]=[/color][color=#ff00ff]'你单击了按钮'[/color] [color=#ff0000]ondblclick[/color][color=#0000cc]=[/color]document[color=#0000cc].[/color]form1[color=#0000cc].[/color]button1[color=#0000cc].[/color][color=#ff0000]value[/color][color=#0000cc]=[/color][color=#ff00ff]'你双击了该按钮'[/color][color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000cc]/[/color][color=#0000ff]form[/color][color=#0000cc]>[/color]
3[color=#0000cc].[/color]创建悬停按钮
[color=#0000cc]<[/color][color=#0000ff]img[/color] [color=#ff0000]src[/color][color=#0000cc]=[/color]go[color=#0000cc].[/color]gif [color=#ff0000]onmouseover[/color][color=#0000cc]=[/color]document[color=#0000cc].[/color]images[color=#0000cc][[/color]0[color=#0000cc]][/color][color=#0000cc].[/color][color=#ff0000]src[/color][color=#0000cc]=[/color][color=#ff00ff]'go2.gif'[/color] [color=#ff0000]onmouseout[/color][color=#0000cc]=[/color] document[color=#0000cc].[/color]images[color=#0000cc][[/color]0[color=#0000cc]][/color][color=#0000cc].[/color][color=#ff0000]src[/color][color=#0000cc]=[/color][color=#ff00ff]'go.gif'[/color][color=#0000cc]>[/color]
4[color=#0000cc].[/color]检测按键
[color=#0000cc]<[/color][color=#0000ff]form[/color] [color=#ff0000]name[/color][color=#0000cc]=[/color]form1[color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000ff]input[/color] [color=#ff0000]type[/color][color=#0000cc]=[/color][color=#ff0000]text[/color] [color=#ff0000]name[/color][color=#0000cc]=[/color]text1 [color=#ff0000]value[/color][color=#0000cc]=[/color]hello [color=#ff0000]onkeypress[/color][color=#0000cc]=[/color][color=#ff00ff]"if(window.event.keyCode=='100') document.form1.text1.value='你按了d键'"[/color][color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000cc]/[/color][color=#0000ff]form[/color][color=#0000cc]>[/color]
5[color=#0000cc].[/color]设置焦点
[color=#0000cc]<[/color][color=#0000ff]form[/color] [color=#ff0000]name[/color][color=#0000cc]=[/color]form1[color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000ff]input[/color] [color=#ff0000]type[/color][color=#0000cc]=[/color][color=#ff0000]text[/color] [color=#ff0000]name[/color][color=#0000cc]=[/color]text1 [color=#ff0000]value[/color][color=#0000cc]=[/color]hello
onfous[color=#0000cc]=[/color]document[color=#0000cc].[/color]form1[color=#0000cc].[/color]text1[color=#0000cc].[/color][color=#ff0000]value[/color][color=#0000cc]=[/color][color=#ff00ff]'该文本框获得焦点'[/color]
[color=#ff0000]onblur[/color][color=#0000cc]=[/color]document[color=#0000cc].[/color]form1[color=#0000cc].[/color]text1[color=#0000cc].[/color][color=#ff0000]value[/color][color=#0000cc]=[/color][color=#ff00ff]'该文本框失去焦点'[/color][color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000cc]/[/color][color=#0000ff]form[/color][color=#0000cc]>[/color]
6[color=#0000cc].[/color]检测下拉菜单选择
[color=#0000cc]<[/color][color=#0000ff]form[/color] [color=#ff0000]name[/color][color=#0000cc]=[/color]form1[color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000ff]select[/color] [color=#ff0000]name[/color][color=#0000cc]=[/color]select1 [color=#ff0000]size[/color][color=#0000cc]=[/color]4
[color=#ff0000]onChange[/color][color=#0000cc]=[/color]document[color=#0000cc].[/color]form1[color=#0000cc].[/color]text1[color=#0000cc].[/color][color=#ff0000]value[/color][color=#0000cc]=[/color]document[color=#0000cc].[/color]form1[color=#0000cc].[/color]select1[color=#0000cc].[/color][color=#ff0000]value[/color][color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000ff]option[/color] [color=#ff0000]value[/color][color=#0000cc]=[/color][color=#ff00ff]"北京"[/color][color=#0000cc]>[/color]北京[color=#0000cc]<[/color][color=#0000cc]/[/color][color=#0000ff]option[/color][color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000ff]option[/color] [color=#ff0000]value[/color][color=#0000cc]=[/color][color=#ff00ff]"上海"[/color][color=#0000cc]>[/color]上海[color=#0000cc]<[/color][color=#0000cc]/[/color][color=#0000ff]option[/color][color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000ff]option[/color] [color=#ff0000]value[/color][color=#0000cc]=[/color][color=#ff00ff]"武汉"[/color][color=#0000cc]>[/color]武汉[color=#0000cc]<[/color][color=#0000cc]/[/color][color=#0000ff]option[/color][color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000ff]option[/color] [color=#ff0000]value[/color][color=#0000cc]=[/color][color=#ff00ff]"天津"[/color][color=#0000cc]>[/color]天津[color=#0000cc]<[/color][color=#0000cc]/[/color][color=#0000ff]option[/color][color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000ff]option[/color] [color=#ff0000]value[/color][color=#0000cc]=[/color][color=#ff00ff]"大连"[/color][color=#0000cc]>[/color]大连[color=#0000cc]<[/color][color=#0000cc]/[/color][color=#0000ff]option[/color][color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000cc]/[/color][color=#0000ff]select[/color][color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000ff]input[/color] tppe[color=#0000cc]=[/color][color=#ff0000]text[/color] [color=#ff0000]name[/color][color=#0000cc]=[/color]text1 [color=#ff0000]value[/color][color=#0000cc]=[/color]hello[color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000cc]/[/color][color=#0000ff]form[/color][color=#0000cc]>[/color]
7[color=#0000cc].[/color]创建网页加载和卸载信息
[color=#0000cc]<[/color][color=#0000ff]body[/color] [color=#ff0000]onload[/color][color=#0000cc]=[/color]document[color=#0000cc].[/color]form1[color=#0000cc].[/color]text1[color=#0000cc].[/color][color=#ff0000]value[/color][color=#0000cc]=[/color][color=#ff00ff]'页面加载完毕'[/color] [color=#ff0000]onunload[/color][color=#0000cc]=[/color]alert[color=#0000cc]([/color][color=#ff00ff]'再见,欢迎再来'[/color][color=#0000cc])[/color][color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000ff]form[/color] [color=#ff0000]name[/color][color=#0000cc]=[/color]form1[color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000ff]input[/color] [color=#ff0000]type[/color][color=#0000cc]=[/color][color=#ff0000]text[/color] [color=#ff0000]name[/color][color=#0000cc]=[/color]text1 [color=#ff0000]value[/color][color=#0000cc]=[/color][color=#ff00ff]"页面正在加载 ……"[/color][color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000cc]/[/color][color=#0000ff]form[/color][color=#0000cc]>[/color]
第七章 使用对象
1[color=#0000cc].[/color]理解对象\属性和方法
[color=#0000cc]<[/color][color=#0000ff]body[/color] [color=#ff0000]bgcolor[/color][color=#0000cc]=[/color][color=#ff00ff]"green"[/color][color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000ff]script[/color][color=#0000cc]>[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color][color=#ff00ff]"页面背景颜色是:"[/color][color=#0000cc]+[/color]document[color=#0000cc].[/color][color=#ff0000]bgColor[/color][color=#0000cc])[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color][color=#ff00ff]"页面前景颜色是:"[/color][color=#0000cc]+[/color]document[color=#0000cc].[/color]fgColor[color=#0000cc])[/color]
[color=#0000cc]<[/color][color=#0000cc]/[/color][color=#0000ff]script[/color][color=#0000cc]>[/color]
2[color=#0000cc].[/color]使用网页元素对象
[color=#0000cc]<[/color][color=#0000ff]script[/color][color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000cc]/[/color][color=#0000ff]script[/color][color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000ff]form[/color] [color=#ff0000]name[/color][color=#0000cc]=[/color]form1[color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000ff]textarea[/color] [color=#ff0000]name[/color][color=#0000cc]=[/color]ta1[color=#0000cc]>[/color]dfgfdgfdhfdhdfdfgdf[color=#0000cc]<[/color][color=#0000cc]/[/color][color=#0000ff]textarea[/color][color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000ff]input[/color] [color=#ff0000]type[/color][color=#0000cc]=[/color][color=#0000ff]button[/color] [color=#ff0000]value[/color][color=#0000cc]=[/color][color=#ff00ff]"选择文本"[/color] [color=#ff0000]onclick[/color][color=#0000cc]=[/color]document[color=#0000cc].[/color]form1[color=#0000cc].[/color]ta1[color=#0000cc].[/color][color=#0000ff]select[/color][color=#0000cc]([/color][color=#0000cc])[/color][color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000ff]input[/color] [color=#ff0000]type[/color][color=#0000cc]=[/color][color=#0000ff]button[/color] [color=#ff0000]value[/color][color=#0000cc]=[/color][color=#ff00ff]"显示文本"[/color] [color=#ff0000]onclick[/color][color=#0000cc]=[/color]document[color=#0000cc].[/color]write[color=#0000cc]([/color]document[color=#0000cc].[/color]form1[color=#0000cc].[/color]ta1[color=#0000cc].[/color][color=#ff0000]value[/color][color=#0000cc])[/color][color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000cc]/[/color][color=#0000ff]form[/color][color=#0000cc]>[/color]
3[color=#0000cc].[/color]使用子对象
4[color=#0000cc].[/color]使用预定义对象
[color=#0000cc]<[/color][color=#0000ff]script[/color][color=#0000cc]>[/color]
str1[color=#0000cc]=[/color][color=#ff00ff]"dgdfgdfgdfhf固定法固定法功夫攻打法"[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color]str1[color=#0000cc]+[/color][color=#ff00ff]"<br>"[/color][color=#0000cc])[/color]
str2[color=#0000cc]=[/color]str1[color=#0000cc].[/color]substr[color=#0000cc]([/color]5[color=#0000cc])[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color]str2[color=#0000cc]+[/color][color=#ff00ff]"<br>"[/color][color=#0000cc])[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color][color=#ff00ff]"输出圆的面积:"[/color][color=#0000cc]+[/color]Math[color=#0000cc].[/color]PI[color=#0000cc]*[/color]Math[color=#0000cc].[/color]pow[color=#0000cc]([/color]5[color=#0000cc].[/color]0[color=#0000cc],[/color]2[color=#0000cc])[/color][color=#0000cc])[/color]
[color=#0000cc]<[/color][color=#0000cc]/[/color][color=#0000ff]script[/color][color=#0000cc]>[/color]
5[color=#0000cc].[/color]创建新对象
[color=#0000cc]<[/color][color=#0000ff]script[/color][color=#0000cc]>[/color]
today[color=#0000cc]=[/color]new Date[color=#0000cc]([/color][color=#0000cc])[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color][color=#ff00ff]"今天是"[/color][color=#0000cc]+[/color][color=#0000cc]([/color]today[color=#0000cc].[/color]getMonth[color=#0000cc]([/color][color=#0000cc])[/color][color=#0000cc]+[/color]1[color=#0000cc])[/color][color=#0000cc]+[/color][color=#ff00ff]"月"[/color][color=#0000cc]+[/color]today[color=#0000cc].[/color]getDate[color=#0000cc]([/color][color=#0000cc])[/color][color=#0000cc]+[/color][color=#ff00ff]"日"[/color][color=#0000cc]+[/color][color=#ff00ff]"<br>"[/color][color=#0000cc])[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color][color=#ff00ff]"现在是:"[/color][color=#0000cc]+[/color]today[color=#0000cc].[/color]toLocaleString[color=#0000cc]([/color][color=#0000cc])[/color][color=#0000cc])[/color]
[color=#0000cc]<[/color][color=#0000cc]/[/color][color=#0000ff]script[/color][color=#0000cc]>[/color]
[/color]
Nothing 2008-4-27 19:23
[color=#000000]6[color=#0000cc].[/color]引用当前对象
[color=#0000cc]<[/color][color=#0000ff]form[/color] [color=#ff0000]name[/color][color=#0000cc]=[/color]form1[color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000ff]input[/color] [color=#ff0000]type[/color][color=#0000cc]=[/color][color=#ff0000]text[/color] [color=#ff0000]name[/color][color=#0000cc]=[/color]text1 [color=#ff0000]value[/color][color=#0000cc]=[/color][color=#ff00ff]"dgdgdfgfd"[/color] [color=#ff0000]onclick[/color][color=#0000cc]=[/color]this[color=#0000cc].[/color][color=#0000ff]select[/color][color=#0000cc]([/color][color=#0000cc])[/color][color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000cc]/[/color][color=#0000ff]script[/color][color=#0000cc]>[/color]
7[color=#0000cc].[/color]查看对象属性
[color=#0000cc]<[/color][color=#0000ff]script[/color][color=#0000cc]>[/color]
[color=#ff0000]for[/color][color=#0000cc]([/color]prop in window[color=#0000cc])[/color]
[color=#0000cc]{[/color]document[color=#0000cc].[/color]write[color=#0000cc]([/color][color=#ff00ff]"window."[/color][color=#0000cc]+[/color]prop[color=#0000cc]+[/color][color=#ff00ff]"="[/color][color=#0000cc]+[/color]window[color=#0000cc][[/color]prop[color=#0000cc]][/color][color=#0000cc]+[/color][color=#ff00ff]"<br>"[/color][color=#0000cc])[/color][color=#0000cc];[/color][color=#0000cc]}[/color]
[color=#ff0000]for[/color][color=#0000cc]([/color]prop2 in location[color=#0000cc])[/color]
[color=#0000cc]{[/color]document[color=#0000cc].[/color]write[color=#0000cc]([/color][color=#ff00ff]"location."[/color][color=#0000cc]+[/color]prop2[color=#0000cc]+[/color][color=#ff00ff]"="[/color][color=#0000cc]+[/color]location[color=#0000cc][[/color]prop[color=#0000cc]][/color][color=#0000cc]+[/color][color=#ff00ff]"<br>"[/color][color=#0000cc])[/color][color=#0000cc];[/color][color=#0000cc]}[/color]
[color=#0000cc]<[/color][color=#0000cc]/[/color][color=#0000ff]script[/color][color=#0000cc]>[/color]
8[color=#0000cc].[/color]使用Array对象
[color=#0000cc]<[/color][color=#0000ff]script[/color][color=#0000cc]>[/color]
array[color=#0000cc]=[/color]new Array[color=#0000cc]([/color]10[color=#0000cc])[/color]
array[color=#0000cc][[/color]0[color=#0000cc]][/color][color=#0000cc]=[/color][color=#ff00ff]"bark"[/color]
array[color=#0000cc][[/color]1[color=#0000cc]][/color][color=#0000cc]=[/color][color=#ff00ff]"apple"[/color]
array[color=#0000cc][[/color]2[color=#0000cc]][/color][color=#0000cc]=[/color][color=#ff00ff]"nebula"[/color]
array[color=#0000cc][[/color]3[color=#0000cc]][/color][color=#0000cc]=[/color][color=#ff00ff]"cookie"[/color]
array[color=#0000cc][[/color]4[color=#0000cc]][/color][color=#0000cc]=[/color][color=#ff00ff]"technology"[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color][color=#ff00ff]"数组元素个数是"[/color][color=#0000cc]+[/color]array[color=#0000cc].[/color]Length[color=#0000cc]+[/color][color=#ff00ff]"<br>"[/color][color=#0000cc])[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color][color=#ff00ff]"用 join将数组合并"[/color][color=#0000cc]+[/color]array[color=#0000cc].[/color]join[color=#0000cc]([/color][color=#ff00ff]" "[/color][color=#0000cc])[/color][color=#0000cc]+[/color][color=#ff00ff]"<br>"[/color][color=#0000cc])[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color][color=#ff00ff]" 数组排序"[/color][color=#0000cc]+[/color]array[color=#0000cc].[/color]sort[color=#0000cc]([/color][color=#0000cc])[/color][color=#0000cc])[/color]
[color=#0000cc]<[/color][color=#0000cc]/[/color][color=#0000ff]script[/color][color=#0000cc]>[/color]
9[color=#0000cc].[/color]使用 image 对象
[color=#0000cc]<[/color][color=#0000ff]img[/color] [color=#ff0000]src[/color][color=#0000cc]=[/color][color=#0000cc]*[/color][color=#0000cc]*[/color][color=#0000cc].[/color]gif [color=#ff0000]alt[/color][color=#0000cc]=[/color][color=#ff00ff]"图片提示…."[/color] [color=#ff0000]border[/color][color=#0000cc]=[/color]10[color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000ff]script[/color][color=#0000cc]>[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color][color=#ff00ff]"图片提示是:"[/color][color=#0000cc]+[/color]document[color=#0000cc].[/color]images[color=#0000cc][[/color]0[color=#0000cc]][/color][color=#0000cc].[/color][color=#ff0000]alt[/color][color=#0000cc]+[/color][color=#ff00ff]"<br>"[/color][color=#0000cc])[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color][color=#ff00ff]"图片边框大小是:"[/color][color=#0000cc]+[/color]document[color=#0000cc].[/color]images[color=#0000cc][[/color]0[color=#0000cc]][/color][color=#0000cc].[/color]broder[color=#0000cc])[/color]
[color=#0000cc]<[/color][color=#0000cc]/[/color][color=#0000ff]script[/color][color=#0000cc]>[/color]
10[color=#0000cc].[/color]预加载图像
[color=#0000cc]<[/color][color=#0000ff]script[/color][color=#0000cc]>[/color]
freddy[color=#0000cc]=[/color]new Image[color=#0000cc]([/color][color=#0000cc])[/color]
freddy[color=#0000cc].[/color][color=#ff0000]src[/color][color=#0000cc]=[/color]freddy[color=#0000cc].[/color]gif
[color=#0000cc]<[/color][color=#0000cc]/[/color][color=#0000ff]script[/color][color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000ff]body[/color] [color=#ff0000]onload[/color][color=#0000cc]=[/color]document[color=#0000cc].[/color]images[color=#0000cc][[/color]0[color=#0000cc]][/color][color=#0000cc].[/color][color=#ff0000]src[/color][color=#0000cc]=[/color]freddy[color=#0000cc].[/color][color=#ff0000]src[/color][color=#0000cc]>[/color]
[color=#0000cc],[/color][color=#0000cc]<[/color][color=#0000ff]img[/color] [color=#ff0000]src[/color][color=#0000cc]=[/color][color=#ff00ff]"blank.gif"[/color][color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000cc]/[/color][color=#0000ff]body[/color][color=#0000cc]>[/color]
11[color=#0000cc].[/color]改变图像
[color=#0000cc]<[/color][color=#0000ff]img[/color] [color=#ff0000]src[/color][color=#0000cc]=[/color]freddy[color=#0000cc].[/color]gif[color=#0000cc]>[/color][color=#0000cc]<[/color][color=#0000ff]br[/color][color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000ff]form[/color] [color=#ff0000]name[/color][color=#0000cc]=[/color]form1[color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000ff]input[/color] [color=#ff0000]type[/color][color=#0000cc]=[/color][color=#0000ff]button[/color] [color=#ff0000]name[/color][color=#0000cc]=[/color]button1 [color=#ff0000]value[/color][color=#0000cc]=[/color][color=#ff00ff]"改变图像"[/color] onclickd[color=#0000cc]=[/color]document[color=#0000cc].[/color]images[color=#0000cc][[/color]0[color=#0000cc]][/color][color=#0000cc].[/color][color=#ff0000]src[/color][color=#0000cc]=[/color]dudjp[color=#0000cc].[/color]gif[color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000cc]/[/color][color=#0000ff]form[/color][color=#0000cc]>[/color]
12[color=#0000cc].[/color]使用link和anchor对象
[color=#0000cc]<[/color][color=#0000ff]a[/color] [color=#ff0000]name[/color][color=#0000cc]=[/color]anchor1[color=#0000cc]>[/color]锚点1[color=#0000cc]<[/color][color=#0000ff]br[/color][color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000ff]a[/color] [color=#ff0000]href[/color][color=#0000cc]=[/color]http:[color=#0000cc]/[/color][color=#0000cc]/[/color]www[color=#0000cc].[/color]microsoft[color=#0000cc].[/color]com[color=#0000cc]>[/color]Microsoft[color=#0000cc]<[/color][color=#0000cc]/[/color][color=#0000ff]a[/color][color=#0000cc]>[/color][color=#0000cc]<[/color][color=#0000ff]br[/color][color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000ff]a[/color] [color=#ff0000]href[/color][color=#0000cc]=[/color]http:[color=#0000cc]/[/color][color=#0000cc]/[/color]www[color=#0000cc].[/color]sohu[color=#0000cc].[/color]com[color=#0000cc]>[/color]sohu[color=#0000cc]<[/color][color=#0000cc]/[/color][color=#0000ff]a[/color][color=#0000cc]>[/color][color=#0000cc]<[/color][color=#0000ff]br[/color][color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000ff]a[/color] [color=#ff0000]href[/color][color=#0000cc]=[/color]http:[color=#0000cc]/[/color][color=#0000cc]/[/color]www[color=#0000cc].[/color]sina[color=#0000cc].[/color]com[color=#0000cc].[/color]cn[color=#0000cc]>[/color]sina[color=#0000cc]<[/color][color=#0000cc]/[/color][color=#0000ff]a[/color][color=#0000cc]>[/color][color=#0000cc]<[/color][color=#0000ff]br[/color][color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000ff]script[/color][color=#0000cc]>[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color][color=#ff00ff]"本页面共有"[/color][color=#0000cc]+[/color]document[color=#0000cc].[/color]links[color=#0000cc].[/color]length[color=#0000cc]+[/color][color=#ff00ff]"链接"[/color][color=#0000cc]+[/color][color=#ff00ff]"<br>"[/color][color=#0000cc])[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color][color=#ff00ff]"本页面共有"[/color][color=#0000cc]+[/color]document[color=#0000cc].[/color]anchors[color=#0000cc].[/color]length[color=#0000cc]+[/color][color=#ff00ff]"锚点"[/color][color=#0000cc]+[/color][color=#ff00ff]"<br>"[/color][color=#0000cc])[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color][color=#ff00ff]"第一个链接协议是"[/color][color=#0000cc]+[/color]document[color=#0000cc].[/color]links[color=#0000cc][[/color]0[color=#0000cc]][/color][color=#0000cc].[/color]protocol[color=#0000cc]+[/color][color=#ff00ff]"<br>"[/color][color=#0000cc])[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color][color=#ff00ff]"第一个链接路径是"[/color][color=#0000cc]+[/color]document[color=#0000cc].[/color]links[color=#0000cc][[/color]0[color=#0000cc]][/color][color=#0000cc].[/color]pathnamel[color=#0000cc]+[/color][color=#ff00ff]"<br>"[/color][color=#0000cc])[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color][color=#ff00ff]"第一个链接href是"[/color][color=#0000cc]+[/color]document[color=#0000cc].[/color]links[color=#0000cc][[/color]0[color=#0000cc]][/color][color=#0000cc].[/color]hrefl[color=#0000cc]+[/color][color=#ff00ff]"<br>"[/color][color=#0000cc])[/color]
[color=#0000cc]<[/color][color=#0000cc]/[/color][color=#0000ff]script[/color][color=#0000cc]>[/color]
13[color=#0000cc].[/color]改变链接
[color=#0000cc]<[/color][color=#0000ff]a[/color] [color=#ff0000]href[/color] [color=#0000cc]=[/color]http:[color=#0000cc]/[/color][color=#0000cc]/[/color]www[color=#0000cc].[/color]microsoft[color=#0000cc].[/color]com[color=#0000cc]>[/color][color=#0000ff]link[/color][color=#0000cc]<[/color][color=#0000cc]/[/color][color=#0000ff]a[/color][color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000ff]form[/color] [color=#ff0000]name[/color][color=#0000cc]=[/color]form1[color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000ff]input[/color] [color=#ff0000]type[/color][color=#0000cc]=[/color][color=#0000ff]button[/color] [color=#ff0000]name[/color][color=#0000cc]=[/color]button1 [color=#ff0000]value[/color][color=#0000cc]=[/color][color=#ff00ff]"改变链接"[/color] [color=#ff0000]onclick[/color][color=#0000cc]=[/color]document[color=#0000cc].[/color]links[color=#0000cc][[/color]0[color=#0000cc]][/color][color=#0000cc].[/color][color=#ff0000]href[/color][color=#0000cc]=[/color][color=#ff00ff]'http://www.sohu.com'[/color][color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000cc]/[/color][color=#0000ff]form[/color][color=#0000cc]>[/color]
14[color=#0000cc].[/color]使用history对象
[color=#0000cc]<[/color][color=#0000ff]form[/color] [color=#ff0000]name[/color][color=#0000cc]=[/color]form1[color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000ff]input[/color] [color=#ff0000]type[/color][color=#0000cc]=[/color][color=#0000ff]button[/color] [color=#ff0000]name[/color][color=#0000cc]=[/color]button1 [color=#ff0000]value[/color][color=#0000cc]=[/color][color=#ff00ff]"向后返回2页"[/color] [color=#ff0000]onclick[/color][color=#0000cc]=[/color]window[color=#0000cc].[/color]history[color=#0000cc].[/color]go[color=#0000cc]([/color][color=#0000cc]-[/color]2[color=#0000cc])[/color][color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000cc]/[/color][color=#0000ff]form[/color][color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000ff]form[/color] [color=#ff0000]name[/color][color=#0000cc]=[/color]form1[color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000ff]input[/color] [color=#ff0000]type[/color][color=#0000cc]=[/color][color=#ff0000]text[/color] [color=#ff0000]name[/color][color=#0000cc]=[/color]text1 [color=#ff0000]value[/color][color=#0000cc]=[/color]hello[color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000cc]/[/color][color=#0000ff]form[/color][color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000ff]script[/color][color=#0000cc]>[/color]
document[color=#0000cc].[/color]form1[color=#0000cc].[/color]text1[color=#0000cc].[/color][color=#ff0000]value[/color][color=#0000cc]=[/color][color=#ff00ff]"gdfgfd"[/color]
[color=#0000cc]<[/color][color=#0000cc]/[/color][color=#0000ff]script[/color][color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000ff]form[/color] [color=#ff0000]name[/color][color=#0000cc]=[/color]form1[color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000ff]input[/color] [color=#ff0000]type[/color][color=#0000cc]=[/color]radio [color=#ff0000]name[/color][color=#0000cc]=[/color]radio1[color=#0000cc]>[/color]男
[color=#0000cc]<[/color][color=#0000ff]input[/color] [color=#ff0000]type[/color][color=#0000cc]=[/color]radio [color=#ff0000]name[/color][color=#0000cc]=[/color]radio2[color=#0000cc]>[/color]女
[color=#0000cc]<[/color][color=#0000cc]/[/color][color=#0000ff]script[/color][color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000ff]script[/color][color=#0000cc]>[/color]
document[color=#0000cc].[/color]form1[color=#0000cc].[/color]radio1[color=#0000cc].[/color][color=#ff0000]checked[/color][color=#0000cc]=[/color]true
[color=#0000cc]<[/color][color=#0000cc]/[/color][color=#0000ff]script[/color][color=#0000cc]>[/color]
第八章 使用窗口
1[color=#0000cc].[/color]在浏览器的状态栏上显示文本
[color=#0000cc]<[/color][color=#0000ff]body[/color] [color=#ff0000]onload[/color][color=#0000cc]=[/color]window[color=#0000cc].[/color]status[color=#0000cc]=[/color][color=#ff00ff]"欢迎光临我的站点"[/color][color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000ff]a[/color] [color=#ff0000]href[/color][color=#0000cc]=[/color]http:[color=#0000cc]/[/color][color=#0000cc]/[/color]www[color=#0000cc].[/color]sohu[color=#0000cc].[/color]com[color=#0000cc]>[/color]sohu[color=#0000cc]<[/color][color=#0000cc]/[/color][color=#0000ff]a[/color][color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000cc]/[/color][color=#0000ff]body[/color][color=#0000cc]>[/color]
2[color=#0000cc].[/color]改变背景色
[color=#0000cc]<[/color][color=#0000ff]script[/color][color=#0000cc]>[/color]
document[color=#0000cc].[/color][color=#ff0000]bgColor[/color][color=#0000cc]=[/color][color=#ff00ff]"orange"[/color]
[color=#0000cc]<[/color][color=#0000cc]/[/color][color=#0000ff]script[/color][color=#0000cc]>[/color]
3[color=#0000cc].[/color]列举背景颜色
[color=#0000cc]<[/color][color=#0000ff]body[/color] [color=#ff0000]bgColor[/color] [color=#0000cc]=[/color]green[color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000ff]script[/color][color=#0000cc]>[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color][color=#ff00ff]"当前背景色是:"[/color][color=#0000cc]+[/color]document[color=#0000cc].[/color][color=#ff0000]bgColor[/color][color=#0000cc])[/color]
[color=#0000cc]<[/color][color=#0000cc]/[/color][color=#0000ff]script[/color][color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000cc]/[/color][color=#0000ff]body[/color][color=#0000cc]>[/color]
4[color=#0000cc].[/color]改变文本和链接颜色
[color=#0000cc]<[/color][color=#0000ff]script[/color][color=#0000cc]>[/color]
document[color=#0000cc].[/color][color=#ff0000]bgColor[/color][color=#0000cc]=[/color][color=#ff00ff]"orange"[/color]
document[color=#0000cc].[/color]fgColor[color=#0000cc]=[/color][color=#ff00ff]"blue"[/color]
document[color=#0000cc].[/color]linkColor[color=#0000cc]=[/color][color=#ff00ff]"red"[/color]
[color=#0000cc]<[/color][color=#0000cc]/[/color][color=#0000ff]script[/color][color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000ff]h2[/color][color=#0000cc]>[/color]看看这段文本颜色[color=#0000cc]<[/color][color=#0000cc]/[/color][color=#0000ff]h2[/color][color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000ff]a[/color] [color=#ff0000]href[/color][color=#0000cc]=[/color]http:[color=#0000cc]/[/color][color=#0000cc]/[/color]www[color=#0000cc].[/color]sohu[color=#0000cc].[/color]com[color=#0000cc]>[/color]sohu[color=#0000cc]<[/color][color=#0000cc]/[/color][color=#0000ff]a[/color][color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000cc]/[/color][color=#0000ff]body[/color][color=#0000cc]>[/color]
5[color=#0000cc].[/color]改变文档标题
[color=#0000cc]<[/color][color=#0000ff]script[/color][color=#0000cc]>[/color]
[color=#ff0000]name[/color][color=#0000cc]=[/color][color=#ff00ff]"Mouse"[/color]
document[color=#0000cc].[/color][color=#0000ff]title[/color][color=#0000cc]=[/color][color=#ff00ff]"welcome to "[/color][color=#0000cc]+[/color][color=#ff0000]name[/color][color=#0000cc]+[/color][color=#ff00ff]"'s House"[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color]document[color=#0000cc].[/color][color=#0000ff]title[/color][color=#0000cc])[/color]
[color=#0000cc]<[/color][color=#0000cc]/[/color][color=#0000ff]script[/color][color=#0000cc]>[/color]
6[color=#0000cc].[/color]显示修改日期
[color=#0000cc]<[/color][color=#0000ff]script[/color][color=#0000cc]>[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color][color=#ff00ff]"本页面最后修改时间是"[/color][color=#0000cc]+[/color]document[color=#0000cc].[/color]lastModified[color=#0000cc])[/color]
[color=#0000cc]<[/color][color=#0000cc]/[/color][color=#0000ff]script[/color][color=#0000cc]>[/color]
7[color=#0000cc].[/color]查看当前文档的URL
[color=#0000cc]<[/color][color=#0000ff]script[/color][color=#0000cc]>[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color][color=#ff00ff]"本页面的URL:"[/color][color=#0000cc]+[/color]document[color=#0000cc].[/color]URL[color=#0000cc])[/color]
[color=#0000cc]<[/color][color=#0000cc]/[/color][color=#0000ff]script[/color][color=#0000cc]>[/color]
8[color=#0000cc].[/color]查看引用页
[color=#0000cc]<[/color][color=#0000ff]script[/color][color=#0000cc]>[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color][color=#ff00ff]"本页面的引用页是"[/color][color=#0000cc]+[/color]document[color=#0000cc].[/color]referrer[color=#0000cc])[/color]
[color=#0000cc]<[/color][color=#0000cc]/[/color][color=#0000ff]script[/color][color=#0000cc]>[/color]
9[color=#0000cc].[/color]打开新的浏览器窗口
[color=#0000cc]<[/color][color=#0000ff]script[/color][color=#0000cc]>[/color]
window[color=#0000cc].[/color]open[color=#0000cc]([/color][color=#ff00ff]"*.htm"[/color][color=#0000cc],[/color][color=#ff00ff]"title"[/color][color=#0000cc],[/color][color=#ff00ff]"width=200,height=400,resizable=yes"[/color][color=#0000cc])[/color]
[color=#0000cc]<[/color][color=#0000cc]/[/color][color=#0000ff]script[/color][color=#0000cc]>[/color]
10[color=#0000cc].[/color]关闭远程窗口
11[color=#0000cc].[/color]打印窗口
[color=#0000cc]<[/color][color=#0000ff]script[/color][color=#0000cc]>[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color][color=#ff00ff]"正文"[/color][color=#0000cc])[/color]
[color=#0000cc]<[/color][color=#0000cc]/[/color][color=#0000ff]script[/color][color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000ff]form[/color] [color=#ff0000]name[/color][color=#0000cc]=[/color]form1[color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000ff]input[/color] [color=#ff0000]type[/color][color=#0000cc]=[/color][color=#0000ff]button[/color] [color=#ff0000]value[/color][color=#0000cc]=[/color]打印 [color=#ff0000]onclick[/color][color=#0000cc]=[/color]window[color=#0000cc].[/color]print[color=#0000cc]([/color][color=#0000cc])[/color][color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000cc]/[/color][color=#0000ff]form[/color][color=#0000cc]>[/color]
12[color=#0000cc].[/color]移动窗口
[color=#0000cc]<[/color][color=#0000ff]form[/color] [color=#ff0000]name[/color][color=#0000cc]=[/color]form1[color=#0000cc]>[/color]
水平方向[color=#0000cc]<[/color][color=#0000ff]input[/color] [color=#ff0000]type[/color][color=#0000cc]=[/color][color=#ff0000]text[/color] [color=#ff0000]name[/color][color=#0000cc]=[/color]x [color=#ff0000]value[/color][color=#0000cc]=[/color]20[color=#0000cc]>[/color]
垂直方向[color=#0000cc]<[/color][color=#0000ff]input[/color] [color=#ff0000]type[/color][color=#0000cc]=[/color][color=#ff0000]text[/color] [color=#ff0000]name[/color][color=#0000cc]=[/color]y [color=#ff0000]value[/color][color=#0000cc]=[/color]50[color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000ff]input[/color] [color=#ff0000]type[/color][color=#0000cc]=[/color][color=#0000ff]button[/color] [color=#ff0000]value[/color][color=#0000cc]=[/color][color=#ff00ff]"移动窗口到…"[/color][color=#ff0000]onclick[/color][color=#0000cc]=[/color]window[color=#0000cc].[/color]moveTo[color=#0000cc]([/color]document[color=#0000cc].[/color]form1[color=#0000cc].[/color]x[color=#0000cc].[/color][color=#ff0000]value[/color][color=#0000cc],[/color]document[color=#0000cc].[/color]form1[color=#0000cc].[/color]y[color=#0000cc].[/color][color=#ff0000]value[/color][color=#0000cc])[/color][color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000cc]/[/color][color=#0000ff]form[/color][color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000ff]form[/color] [color=#ff0000]name[/color][color=#0000cc]=[/color]form1[color=#0000cc]>[/color]
水平方向[color=#0000cc]<[/color][color=#0000ff]input[/color] [color=#ff0000]type[/color][color=#0000cc]=[/color][color=#ff0000]text[/color] [color=#ff0000]name[/color][color=#0000cc]=[/color]x [color=#ff0000]value[/color][color=#0000cc]=[/color]20[color=#0000cc]>[/color]
垂直方向[color=#0000cc]<[/color][color=#0000ff]input[/color] [color=#ff0000]type[/color][color=#0000cc]=[/color][color=#ff0000]text[/color] [color=#ff0000]name[/color][color=#0000cc]=[/color]y [color=#ff0000]value[/color][color=#0000cc]=[/color]50[color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000ff]input[/color] [color=#ff0000]type[/color][color=#0000cc]=[/color][color=#0000ff]button[/color] [color=#ff0000]value[/color][color=#0000cc]=[/color][color=#ff00ff]"移动窗口"[/color][color=#ff0000]onclick[/color][color=#0000cc]=[/color]window[color=#0000cc].[/color]moveBy[color=#0000cc]([/color]document[color=#0000cc].[/color]form1[color=#0000cc].[/color]x[color=#0000cc].[/color][color=#ff0000]value[/color][color=#0000cc],[/color]document[color=#0000cc].[/color]form1[color=#0000cc].[/color]y[color=#0000cc].[/color][color=#ff0000]value[/color][color=#0000cc])[/color][color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000cc]/[/color][color=#0000ff]form[/color][color=#0000cc]>[/color]
13[color=#0000cc].[/color]改变窗口大小
14[color=#0000cc].[/color]用警告对话框通知用户
[color=#0000cc]<[/color][color=#0000ff]script[/color][color=#0000cc]>[/color]
window[color=#0000cc].[/color]alert[color=#0000cc]([/color][color=#ff00ff]"welcome"[/color][color=#0000cc])[/color]
[color=#0000cc]<[/color][color=#0000cc]/[/color][color=#0000ff]script[/color][color=#0000cc]>[/color]
15[color=#0000cc].[/color]用提示对话框接受输入
[color=#0000cc]<[/color][color=#0000ff]script[/color][color=#0000cc]>[/color]
[color=#ff0000]name[/color][color=#0000cc]=[/color]window[color=#0000cc].[/color][color=#ff0000]prompt[/color][color=#0000cc]([/color][color=#ff00ff]"输入姓名"[/color][color=#0000cc],[/color][color=#ff00ff]"姓名"[/color][color=#0000cc])[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color][color=#ff00ff]" 欢迎您:"[/color][color=#0000cc]+[/color][color=#ff0000]name[/color][color=#0000cc]+[/color][color=#ff00ff]"来到这里"[/color][color=#0000cc])[/color]
[color=#0000cc]<[/color][color=#0000cc]/[/color][color=#0000ff]script[/color][color=#0000cc]>[/color]
16[color=#0000cc].[/color]用确认对话框使用户做出决定
[color=#0000cc]<[/color][color=#0000ff]script[/color][color=#0000cc]>[/color]
like[color=#0000cc]=[/color]window[color=#0000cc].[/color]confirm[color=#0000cc]([/color][color=#ff00ff]"你觉得好吗?"[/color][color=#0000cc])[/color]
if[color=#0000cc]([/color]like[color=#0000cc]=[/color][color=#0000cc]=[/color]true[color=#0000cc])[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color][color=#ff00ff]"谢谢你的夸奖"[/color][color=#0000cc])[/color]
else
document[color=#0000cc].[/color]write[color=#0000cc]([/color][color=#ff00ff]"希望得到你的夸奖"[/color][color=#0000cc])[/color]
[color=#0000cc]<[/color][color=#0000cc]/[/color][color=#0000ff]script[/color][color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000ff]form[/color] [color=#ff0000]name[/color][color=#0000cc]=[/color]form1[color=#0000cc]>[/color]
水平方向[color=#0000cc]<[/color][color=#0000ff]input[/color] [color=#ff0000]type[/color][color=#0000cc]=[/color][color=#ff0000]text[/color] [color=#ff0000]name[/color][color=#0000cc]=[/color]x [color=#ff0000]value[/color][color=#0000cc]=[/color]200[color=#0000cc]>[/color]
垂直方向[color=#0000cc]<[/color][color=#0000ff]input[/color] [color=#ff0000]type[/color][color=#0000cc]=[/color][color=#ff0000]text[/color] [color=#ff0000]name[/color][color=#0000cc]=[/color]y [color=#ff0000]value[/color][color=#0000cc]=[/color]500[color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000ff]input[/color] [color=#ff0000]type[/color][color=#0000cc]=[/color][color=#0000ff]button[/color] [color=#ff0000]value[/color][color=#0000cc]=[/color][color=#ff00ff]"改变窗口大小到….."[/color][color=#ff0000]onclick[/color][color=#0000cc]=[/color]window[color=#0000cc].[/color]resizeTo[color=#0000cc]([/color]document[color=#0000cc].[/color]form1[color=#0000cc].[/color]x[color=#0000cc].[/color][color=#ff0000]value[/color][color=#0000cc],[/color]document[color=#0000cc].[/color]form1[color=#0000cc].[/color]y[color=#0000cc].[/color][color=#ff0000]value[/color][color=#0000cc])[/color][color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000cc]/[/color][color=#0000ff]form[/color][color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000ff]form[/color] [color=#ff0000]name[/color][color=#0000cc]=[/color]form1[color=#0000cc]>[/color]
水平方向[color=#0000cc]<[/color][color=#0000ff]input[/color] [color=#ff0000]type[/color][color=#0000cc]=[/color][color=#ff0000]text[/color] [color=#ff0000]name[/color][color=#0000cc]=[/color]x [color=#ff0000]value[/color][color=#0000cc]=[/color]200[color=#0000cc]>[/color]
垂直方向[color=#0000cc]<[/color][color=#0000ff]input[/color] [color=#ff0000]type[/color][color=#0000cc]=[/color][color=#ff0000]text[/color] [color=#ff0000]name[/color][color=#0000cc]=[/color]y [color=#ff0000]value[/color][color=#0000cc]=[/color]500[color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000ff]input[/color] [color=#ff0000]type[/color][color=#0000cc]=[/color][color=#0000ff]button[/color] [color=#ff0000]value[/color][color=#0000cc]=[/color][color=#ff00ff]"改变窗口大小"[/color][color=#ff0000]onclick[/color][color=#0000cc]=[/color]window[color=#0000cc].[/color]resizeBy[color=#0000cc]([/color]document[color=#0000cc].[/color]form1[color=#0000cc].[/color]x[color=#0000cc].[/color][color=#ff0000]value[/color][color=#0000cc],[/color]document[color=#0000cc].[/color]form1[color=#0000cc].[/color]y[color=#0000cc].[/color][color=#ff0000]value[/color][color=#0000cc])[/color][color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000cc]/[/color][color=#0000ff]form[/color][color=#0000cc]>[/color]
close[color=#0000cc].[/color][color=#0000ff]html[/color][color=#0000ff]:[/color]
[color=#0000cc]<[/color][color=#0000ff]script[/color][color=#0000cc]>[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color][color=#ff00ff]"正文"[/color][color=#0000cc])[/color]
[color=#0000cc]<[/color][color=#0000cc]/[/color][color=#0000ff]script[/color][color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000ff]form[/color] [color=#ff0000]name[/color][color=#0000cc]=[/color]form1[color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000ff]input[/color] [color=#ff0000]type[/color][color=#0000cc]=[/color][color=#0000ff]button[/color] [color=#ff0000]name[/color][color=#0000cc]=[/color]button1value[color=#0000cc]=[/color][color=#ff00ff]"关闭"[/color] [color=#ff0000]onclick[/color][color=#0000cc]=[/color]window[color=#0000cc].[/color]close[color=#0000cc]([/color][color=#0000cc])[/color][color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000cc]/[/color][color=#0000ff]form[/color][color=#0000cc]>[/color]
open[color=#0000cc].[/color][color=#0000ff]html[/color]
[color=#0000cc]<[/color][color=#0000ff]script[/color][color=#0000cc]>[/color]
window[color=#0000cc].[/color]open[color=#0000cc]([/color][color=#ff00ff]"close.html"[/color][color=#0000cc],[/color][color=#ff00ff]"romote"[/color][color=#0000cc],[/color][color=#ff00ff]"width=200,height=400,resizable=yes"[/color][color=#0000cc])[/color]
[color=#0000cc]<[/color][color=#0000cc]/[/color][color=#0000ff]script[/color][color=#0000cc]>[/color] [/color]
Nothing 2008-4-27 19:24
[color=#000000]第九章 使用字符串
1[color=#0000cc].[/color]使用字符串对象
[color=#0000cc]<[/color][color=#0000ff]script[/color][color=#0000cc]>[/color]
mystring[color=#0000cc]=[/color][color=#ff00ff]"gdgdfgfddddaaaaaaaaaaaabbbbbbbbbbbbbbbbbvbhg.<br>"[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color]mystring[color=#0000cc])[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color]mystring[color=#0000cc].[/color]bold[color=#0000cc]([/color][color=#0000cc])[/color][color=#0000cc])[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color]mystring[color=#0000cc].[/color]toUpperCase[color=#0000cc]([/color][color=#0000cc])[/color][color=#0000cc])[/color]
[color=#0000cc]<[/color][color=#0000cc]/[/color][color=#0000ff]script[/color][color=#0000cc]>[/color]
2[color=#0000cc].[/color]使用子字符串
[color=#0000cc]<[/color][color=#0000ff]script[/color][color=#0000cc]>[/color]
str1[color=#0000cc]=[/color][color=#ff00ff]"fdsf 1111 gfdgfd dfdsf cccc dddd.<br>"[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color]str1[color=#0000cc])[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color]str1[color=#0000cc].[/color]substring[color=#0000cc]([/color]0[color=#0000cc],[/color]13[color=#0000cc])[/color][color=#0000cc]+[/color][color=#ff00ff]"<br>"[/color][color=#0000cc])[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color]str1[color=#0000cc].[/color]substr [color=#0000cc]([/color]20[color=#0000cc],[/color]11[color=#0000cc])[/color][color=#0000cc]+[/color][color=#ff00ff]"<br>"[/color][color=#0000cc])[/color]
[color=#0000cc]<[/color][color=#0000cc]/[/color][color=#0000ff]script[/color][color=#0000cc]>[/color]
3[color=#0000cc].[/color]连接字符串
[color=#0000cc]<[/color][color=#0000ff]script[/color][color=#0000cc]>[/color]
str1[color=#0000cc]=[/color][color=#ff00ff]"may you find"[/color]
str2[color=#0000cc]=[/color][color=#ff00ff]"peace,happiness and prosperity.<br>"[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color]str1[color=#0000cc]+[/color][color=#ff00ff]"<br>"[/color][color=#0000cc])[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color]str2[color=#0000cc])[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color]str1[color=#0000cc].[/color]concat[color=#0000cc]([/color]str2[color=#0000cc])[/color][color=#0000cc])[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color]str1[color=#0000cc]+[/color][color=#0000cc]=[/color]str2[color=#0000cc])[/color]
[color=#0000cc]<[/color][color=#0000cc]/[/color][color=#0000ff]script[/color][color=#0000cc]>[/color]
4[color=#0000cc].[/color]格式化字符串变量
[color=#0000cc]<[/color][color=#0000ff]script[/color][color=#0000cc]>[/color]
str1[color=#0000cc]=[/color][color=#ff00ff]"peace,happiness and prosperity.<br>"[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color]str1[color=#0000cc])[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color]str1[color=#0000cc].[/color][color=#0000ff]big[/color][color=#0000cc]([/color][color=#0000cc])[/color][color=#0000cc])[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color]str1[color=#0000cc].[/color][color=#0000ff]small[/color][color=#0000cc]([/color][color=#0000cc])[/color][color=#0000cc])[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color]str1[color=#0000cc].[/color]bold[color=#0000cc]([/color][color=#0000cc])[/color][color=#0000cc])[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color]str1[color=#0000cc].[/color]italics[color=#0000cc]([/color][color=#0000cc])[/color][color=#0000cc])[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color]str1[color=#0000cc].[/color][color=#0000ff]strike[/color][color=#0000cc]([/color][color=#0000cc])[/color][color=#0000cc])[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color]str1[color=#0000cc].[/color]fontsize[color=#0000cc]([/color]6[color=#0000cc])[/color][color=#0000cc])[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color]str1[color=#0000cc].[/color]fontcolor[color=#0000cc]([/color]green[color=#0000cc])[/color][color=#0000cc])[/color]
[color=#0000cc]<[/color][color=#0000cc]/[/color][color=#0000ff]script[/color][color=#0000cc]>[/color]
5[color=#0000cc].[/color]创建锚和链接
[color=#0000cc]<[/color][color=#0000ff]script[/color][color=#0000cc]>[/color]
str1[color=#0000cc]=[/color][color=#ff00ff]"this is the bigginning of the page.<br>"[/color]
str2[color=#0000cc]=[/color][color=#ff00ff]"….<br>"[/color]
str3[color=#0000cc]=[/color][color=#ff00ff]"this is the end of the page .<br>"[/color]
str4[color=#0000cc]=[/color][color=#ff00ff]"link to the start<br>"[/color]
str5[color=#0000cc]=[/color][color=#ff00ff]"link to the end<br>"[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color]str1[color=#0000cc].[/color]anchor[color=#0000cc]([/color][color=#ff00ff]"start"[/color][color=#0000cc])[/color][color=#0000cc])[/color]
[color=#ff0000]for[/color][color=#0000cc]([/color][color=#0000ff]i[/color][color=#0000cc]=[/color]0[color=#0000cc];[/color][color=#0000ff]i[/color][color=#0000cc]<[/color]10[color=#0000cc];[/color][color=#0000ff]i[/color][color=#0000cc]+[/color][color=#0000cc]+[/color][color=#0000cc])[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color]str2[color=#0000cc])[/color][color=#0000cc];[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color]str3[color=#0000cc].[/color]anchor[color=#0000cc]([/color][color=#ff00ff]"end"[/color][color=#0000cc])[/color][color=#0000cc])[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color]str4[color=#0000cc].[/color][color=#0000ff]link[/color][color=#0000cc]([/color][color=#ff00ff]"#start"[/color][color=#0000cc])[/color][color=#0000cc])[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color]str5[color=#0000cc].[/color][color=#0000ff]link[/color][color=#0000cc]([/color][color=#ff00ff]"#end"[/color][color=#0000cc])[/color][color=#0000cc])[/color]
[color=#0000cc]<[/color][color=#0000cc]/[/color][color=#0000ff]script[/color][color=#0000cc]>[/color]
6[color=#0000cc].[/color]确定字符串长度
[color=#0000cc]<[/color][color=#0000ff]script[/color][color=#0000cc]>[/color]
str1[color=#0000cc]=[/color][color=#ff00ff]"this is the bigginning of the page."[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color]str1[color=#0000cc]+[/color][color=#ff00ff]"<br>"[/color][color=#0000cc])[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color] [color=#ff00ff]"字符串的长度是:"[/color][color=#0000cc]+[/color]str1[color=#0000cc].[/color]length[color=#0000cc])[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color][color=#ff00ff]"字符串全部大写是;"[/color][color=#0000cc]+[/color]str1[color=#0000cc].[/color]toUpperCase[color=#0000cc]([/color][color=#0000cc])[/color][color=#0000cc])[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color][color=#ff00ff]"字符串全部小写是;"[/color][color=#0000cc]+[/color]str1[color=#0000cc].[/color]toLowerCase[color=#0000cc]([/color][color=#0000cc])[/color][color=#0000cc])[/color]
[color=#0000cc]<[/color][color=#0000cc]/[/color][color=#0000ff]script[/color][color=#0000cc]>[/color]
7[color=#0000cc].[/color]在字符串内搜索
[color=#0000cc]<[/color][color=#0000ff]script[/color][color=#0000cc]>[/color]
str1[color=#0000cc]=[/color][color=#ff00ff]"this is the end of the line.<br>"[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color]str1[color=#0000cc])[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color][color=#ff00ff]"字符end在字符串的位置是"[/color][color=#0000cc]+[/color]str1[color=#0000cc].[/color]search[color=#0000cc]([/color][color=#ff00ff]"end"[/color][color=#0000cc])[/color][color=#0000cc])[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color][color=#ff00ff]"字符dog在字符串的位置是"[/color][color=#0000cc]+[/color]str1[color=#0000cc].[/color]search[color=#0000cc]([/color][color=#ff00ff]"dog"[/color][color=#0000cc])[/color][color=#0000cc])[/color]
[color=#0000cc]<[/color][color=#0000cc]/[/color][color=#0000ff]script[/color][color=#0000cc]>[/color]
8[color=#0000cc].[/color]定位字符串中的字符
[color=#0000cc]<[/color][color=#0000ff]script[/color][color=#0000cc]>[/color]
str1[color=#0000cc]=[/color][color=#ff00ff]"spring is a time for flowers and trees and baby bunnles<br>"[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color]str1[color=#0000cc])[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color][color=#ff00ff]"the index for the second word ‘and' is"[/color][color=#0000cc]+[/color]str1[color=#0000cc].[/color]indexOf[color=#0000cc]([/color][color=#ff00ff]"and"[/color][color=#0000cc],[/color]30[color=#0000cc])[/color][color=#0000cc])[/color]
documednt[color=#0000cc].[/color]write[color=#0000cc]([/color][color=#ff00ff]"the last index of the word ‘and' is "[/color][color=#0000cc]+[/color]str1[color=#0000cc].[/color]lastIndexOf[color=#0000cc]([/color][color=#ff00ff]"and"[/color][color=#0000cc])[/color][color=#0000cc])[/color]
[color=#0000cc]<[/color][color=#0000cc]/[/color][color=#0000ff]script[/color][color=#0000cc]>[/color]
9[color=#0000cc].[/color]替换字符串中的文本
[color=#0000cc]<[/color][color=#0000ff]script[/color][color=#0000cc]>[/color]
str1[color=#0000cc]=[/color][color=#ff00ff]"spring is a time for flowers and trees and baby bunnles<br>"[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color]str1[color=#0000cc])[/color]
document [color=#0000cc].[/color]write[color=#0000cc]([/color]str1[color=#0000cc].[/color]replace[color=#0000cc]([/color][color=#ff00ff]"and"[/color][color=#0000cc],[/color][color=#ff00ff]","[/color][color=#0000cc])[/color][color=#0000cc])[/color]
[color=#0000cc]<[/color][color=#0000cc]/[/color][color=#0000ff]script[/color][color=#0000cc]>[/color]
10[color=#0000cc].[/color]字符串分离
[color=#0000cc]<[/color][color=#0000ff]script[/color][color=#0000cc]>[/color]
str1[color=#0000cc]=[/color][color=#ff00ff]"spring is a time for flowers and trees and baby bunnles<br>"[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color]str1[color=#0000cc])[/color]
str1array[color=#0000cc]=[/color]str1[color=#0000cc].[/color]split[color=#0000cc]([/color][color=#ff00ff]" "[/color][color=#0000cc])[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color]str1array[color=#0000cc][[/color]0[color=#0000cc]][/color][color=#0000cc]+[/color][color=#ff00ff]"<br>"[/color][color=#0000cc])[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color]str1array[color=#0000cc][[/color]1[color=#0000cc]][/color][color=#0000cc]+[/color][color=#ff00ff]"<br>"[/color][color=#0000cc])[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color]str1array[color=#0000cc][[/color]2[color=#0000cc]][/color][color=#0000cc]+[/color][color=#ff00ff]"<br>"[/color][color=#0000cc])[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color]str1array[color=#0000cc][[/color]3[color=#0000cc]][/color][color=#0000cc]+[/color][color=#ff00ff]"<br>"[/color][color=#0000cc])[/color]
[color=#0000cc]<[/color][color=#0000cc]/[/color][color=#0000ff]script[/color][color=#0000cc]>[/color]
第十章 使用日期和时间
1[color=#0000cc].[/color]使用Date对象
[color=#0000cc]<[/color][color=#0000ff]script[/color][color=#0000cc]>[/color]
cdate[color=#0000cc]=[/color]new Date[color=#0000cc]([/color][color=#ff00ff]"august 2,1989 12:30:00"[/color][color=#0000cc])[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color]cdate[color=#0000cc])[/color]
[color=#0000cc]<[/color][color=#0000cc]/[/color][color=#0000ff]script[/color][color=#0000cc]>[/color]
2[color=#0000cc].[/color]显示当地时间和日期
[color=#0000cc]<[/color][color=#0000ff]script[/color][color=#0000cc]>[/color]
cdate[color=#0000cc]=[/color]new Date[color=#0000cc]([/color][color=#0000cc])[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color][color=#ff00ff]"当前时间是:"[/color][color=#0000cc]+[/color]cdate[color=#0000cc].[/color]toGMTString[color=#0000cc]([/color][color=#0000cc])[/color][color=#0000cc]+[/color][color=#ff00ff]"<br>"[/color][color=#0000cc])[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color][color=#ff00ff]"日期和时间是:"[/color][color=#0000cc]+[/color]cdate[color=#0000cc].[/color]toLocaleString[color=#0000cc]([/color][color=#0000cc])[/color][color=#0000cc])[/color]
[color=#0000cc]<[/color][color=#0000cc]/[/color][color=#0000ff]script[/color][color=#0000cc]>[/color]
3[color=#0000cc].[/color]获得时间和日期值
[color=#0000cc]<[/color][color=#0000ff]script[/color][color=#0000cc]>[/color]
cdate[color=#0000cc]=[/color]new Date[color=#0000cc]([/color][color=#0000cc])[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color][color=#ff00ff]"显示当前的星期"[/color][color=#0000cc]+[/color]cdate[color=#0000cc].[/color]getDay[color=#0000cc]([/color][color=#0000cc])[/color][color=#0000cc]+[/color][color=#ff00ff]"<br>"[/color][color=#0000cc])[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color][color=#ff00ff]"显示当前的月份"[/color][color=#0000cc]+[/color]cdate[color=#0000cc].[/color]getMonth[color=#0000cc]([/color][color=#0000cc])[/color][color=#0000cc]+[/color][color=#ff00ff]"<br>"[/color][color=#0000cc])[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color][color=#ff00ff]"显示当前的日期"[/color][color=#0000cc]+[/color]cdate[color=#0000cc].[/color]getDay[color=#0000cc]([/color][color=#0000cc])[/color][color=#0000cc]+[/color][color=#ff00ff]"<br>"[/color][color=#0000cc])[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color][color=#ff00ff]"显示当前的年份"[/color][color=#0000cc]+[/color]cdate[color=#0000cc].[/color]getYear[color=#0000cc]([/color][color=#0000cc])[/color][color=#0000cc]+[/color][color=#ff00ff]"<br>"[/color][color=#0000cc])[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color][color=#ff00ff]"显示当前的小时"[/color][color=#0000cc]+[/color]cdate[color=#0000cc].[/color]getHours[color=#0000cc]([/color][color=#0000cc])[/color][color=#0000cc]+[/color][color=#ff00ff]"<br>"[/color][color=#0000cc])[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color][color=#ff00ff]"显示当前的分钟"[/color][color=#0000cc]+[/color]cdate[color=#0000cc].[/color]getMinutes[color=#0000cc]([/color][color=#0000cc])[/color][color=#0000cc]+[/color][color=#ff00ff]"<br>"[/color][color=#0000cc])[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color][color=#ff00ff]"显示当前的秒"[/color][color=#0000cc]+[/color]cdate[color=#0000cc].[/color]getSeconds[color=#0000cc]([/color][color=#0000cc])[/color][color=#0000cc]+[/color][color=#ff00ff]"<br>"[/color][color=#0000cc])[/color]
[color=#0000cc]<[/color][color=#0000cc]/[/color][color=#0000ff]script[/color][color=#0000cc]>[/color]
4[color=#0000cc].[/color]设置时间和日期值
[color=#0000cc]<[/color][color=#0000ff]script[/color] [color=#ff0000]language[/color][color=#0000cc]=[/color]javascript[color=#0000cc]>[/color]
cdate[color=#0000cc]=[/color]new Date[color=#0000cc]([/color][color=#ff00ff]"December 25,1984"[/color][color=#0000cc])[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color][color=#ff00ff]"显示日期"[/color][color=#0000cc]+[/color]cdate[color=#0000cc]+[/color][color=#ff00ff]"<br>"[/color][color=#0000cc])[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color][color=#ff00ff]"设置月份"[/color][color=#0000cc]+[/color]cdate[color=#0000cc].[/color]setMonth[color=#0000cc]([/color]10[color=#0000cc])[/color][color=#0000cc]+[/color][color=#ff00ff]"<br>"[/color][color=#0000cc])[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color][color=#ff00ff]"设置日期"[/color][color=#0000cc]+[/color]cdate[color=#0000cc].[/color]setDate[color=#0000cc]([/color]23[color=#0000cc])[/color][color=#0000cc]+[/color][color=#ff00ff]"<br>"[/color][color=#0000cc])[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color][color=#ff00ff]"设置年份"[/color][color=#0000cc]+[/color]cdate[color=#0000cc].[/color]setYear[color=#0000cc]([/color]2000[color=#0000cc])[/color][color=#0000cc]+[/color][color=#ff00ff]"<br>"[/color][color=#0000cc])[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color][color=#ff00ff]"设置小时"[/color][color=#0000cc]+[/color]cdate[color=#0000cc].[/color]setHours[color=#0000cc]([/color]13[color=#0000cc])[/color][color=#0000cc]+[/color][color=#ff00ff]"<br>"[/color][color=#0000cc])[/color][color=#0000cc];[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color][color=#ff00ff]"设置分钟"[/color][color=#0000cc]+[/color]cdate[color=#0000cc].[/color]setMinutes[color=#0000cc]([/color]47[color=#0000cc])[/color][color=#0000cc]+[/color][color=#ff00ff]"<br>"[/color][color=#0000cc])[/color][color=#0000cc];[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color][color=#ff00ff]"设置秒"[/color][color=#0000cc]+[/color]cdate[color=#0000cc].[/color]setSeconds[color=#0000cc]([/color]23[color=#0000cc])[/color][color=#0000cc]+[/color][color=#ff00ff]"<br>"[/color][color=#0000cc])[/color][color=#0000cc];[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color][color=#ff00ff]"显示设置后的日期和时间"[/color][color=#0000cc]+[/color]cdate[color=#0000cc])[/color][color=#0000cc];[/color]
[color=#0000cc]<[/color][color=#0000cc]/[/color][color=#0000ff]script[/color][color=#0000cc]>[/color]
第十一章 使用Math对象
1[color=#0000cc].[/color] 使用Math对象
[color=#0000cc]<[/color][color=#0000ff]script[/color] [color=#ff0000]language[/color][color=#0000cc]=[/color]javascript[color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000cc]/[/color][color=#0000ff]script[/color][color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000ff]form[/color] [color=#ff0000]name[/color][color=#0000cc]=[/color]form1[color=#0000cc]>[/color]
圆的半径:[color=#0000cc]<[/color][color=#0000ff]input[/color] [color=#ff0000]type[/color][color=#0000cc]=[/color][color=#ff0000]text[/color] [color=#ff0000]name[/color][color=#0000cc]=[/color]rad[color=#0000cc]>[/color][color=#0000cc]<[/color][color=#0000ff]br[/color][color=#0000cc]>[/color]
圆的面积:[color=#0000cc]<[/color][color=#0000ff]input[/color] [color=#ff0000]type[/color][color=#0000cc]=[/color][color=#ff0000]text[/color] [color=#ff0000]name[/color][color=#0000cc]=[/color][color=#0000ff]area[/color][color=#0000cc]>[/color][color=#0000cc]<[/color][color=#0000ff]br[/color][color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000ff]input[/color] [color=#ff0000]type[/color][color=#0000cc]=[/color][color=#0000ff]button[/color] [color=#ff0000]name[/color][color=#0000cc]=[/color]button1 [color=#ff0000]value[/color][color=#0000cc]=[/color]计算圆的面积 [color=#ff0000]onclick[/color][color=#0000cc]=[/color]document[color=#0000cc].[/color]form1[color=#0000cc].[/color][color=#0000ff]area[/color][color=#0000cc].[/color][color=#ff0000]value[/color][color=#0000cc]=[/color]document[color=#0000cc].[/color]form1[color=#0000cc].[/color]rad[color=#0000cc].[/color][color=#ff0000]value[/color][color=#0000cc]*[/color]document[color=#0000cc].[/color]
form1[color=#0000cc].[/color]rad[color=#0000cc].[/color][color=#ff0000]value[/color][color=#0000cc]*[/color]Math[color=#0000cc].[/color]PI[color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000cc]/[/color][color=#0000ff]form[/color][color=#0000cc]>[/color]
2[color=#0000cc].[/color]生成随机数
[color=#0000cc]<[/color][color=#0000ff]script[/color][color=#0000cc]>[/color]
array1[color=#0000cc]=[/color]new Array[color=#0000cc]([/color]
[color=#ff00ff]"这是第1句"[/color][color=#0000cc],[/color]
[color=#ff00ff]"这是第2句"[/color][color=#0000cc],[/color]
[color=#ff00ff]"这是第3句"[/color][color=#0000cc],[/color]
[color=#ff00ff]"这是第4句"[/color][color=#0000cc],[/color]
[color=#ff00ff]"这是第5句"[/color][color=#0000cc],[/color]
[color=#ff00ff]"这是第6句"[/color][color=#0000cc])[/color]
RandomNo[color=#0000cc]=[/color]Math[color=#0000cc].[/color]floor[color=#0000cc]([/color]array1[color=#0000cc].[/color]length[color=#0000cc]*[/color]Math[color=#0000cc].[/color]random[color=#0000cc]([/color][color=#0000cc])[/color][color=#0000cc])[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color][color=#ff00ff]"随机输出某一句"[/color][color=#0000cc]+[/color][color=#ff00ff]"<br>"[/color][color=#0000cc]+[/color]array1[color=#0000cc][[/color]RandomNo[color=#0000cc]][/color][color=#0000cc])[/color]
[color=#0000cc]<[/color][color=#0000cc]/[/color][color=#0000ff]script[/color][color=#0000cc]>[/color]
3[color=#0000cc].[/color]使用平方根
[color=#0000cc]<[/color][color=#0000ff]form[/color] [color=#ff0000]name[/color][color=#0000cc]=[/color]form1[color=#0000cc]>[/color]
[color=#ff0000]value[/color][color=#ff0000]:[/color][color=#0000cc]<[/color][color=#0000ff]input[/color] [color=#ff0000]type[/color][color=#0000cc]=[/color][color=#ff0000]text[/color] [color=#ff0000]name[/color][color=#0000cc]=[/color]va1[color=#0000cc]>[/color][color=#0000cc]<[/color][color=#0000ff]br[/color][color=#0000cc]>[/color]
平方根[color=#0000cc]<[/color][color=#0000ff]input[/color] [color=#ff0000]type[/color][color=#0000cc]=[/color][color=#ff0000]text[/color] [color=#ff0000]name[/color][color=#0000cc]=[/color]sqrt[color=#0000cc]>[/color][color=#0000cc]<[/color][color=#0000ff]br[/color][color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000ff]input[/color] [color=#ff0000]type[/color][color=#0000cc]=[/color][color=#0000ff]button[/color] [color=#ff0000]name[/color][color=#0000cc]=[/color]button1 [color=#ff0000]value[/color][color=#0000cc]=[/color]计算平方根
[color=#ff0000]onclick[/color][color=#0000cc]=[/color][color=#ff00ff]"document.form1.sqrt.value=Math.sqrt(document.form1.va1.value)"[/color][color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000cc]/[/color][color=#0000ff]form[/color][color=#0000cc]>[/color]
4[color=#0000cc].[/color]数字的舍入
[color=#0000cc]<[/color][color=#0000ff]form[/color] [color=#ff0000]name[/color][color=#0000cc]=[/color]form1[color=#0000cc]>[/color]
输入[color=#0000cc]<[/color][color=#0000ff]input[/color] [color=#ff0000]type[/color][color=#0000cc]=[/color][color=#ff0000]text[/color] [color=#ff0000]name[/color][color=#0000cc]=[/color]val[color=#0000cc]>[/color][color=#0000cc]<[/color][color=#0000ff]br[/color][color=#0000cc]>[/color]
舍入的结果[color=#0000cc]<[/color][color=#0000ff]input[/color] [color=#ff0000]type[/color][color=#0000cc]=[/color][color=#ff0000]text[/color] [color=#ff0000]name[/color][color=#0000cc]=[/color]round[color=#0000cc]>[/color][color=#0000cc]<[/color][color=#0000ff]br[/color][color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000ff]input[/color] [color=#ff0000]type[/color][color=#0000cc]=[/color][color=#0000ff]button[/color] [color=#ff0000]name[/color][color=#0000cc]=[/color]button1 [color=#ff0000]value[/color][color=#0000cc]=[/color]计算结果 [color=#ff0000]onclick[/color][color=#0000cc]=[/color]document[color=#0000cc].[/color]form1[color=#0000cc].[/color]round[color=#0000cc].[/color][color=#ff0000]value[/color][color=#0000cc]=[/color]Math[color=#0000cc].[/color]round[color=#0000cc]([/color]document[color=#0000cc].[/color]form1[color=#0000cc].[/color]val[color=#0000cc].[/color][color=#ff0000]value[/color][color=#0000cc])[/color][color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000cc]/[/color][color=#0000ff]form[/color][color=#0000cc]>[/color]
5[color=#0000cc].[/color]乘方运算
[color=#0000cc]<[/color][color=#0000ff]form[/color] [color=#ff0000]name[/color][color=#0000cc]=[/color]form1[color=#0000cc]>[/color]
底数[color=#0000cc]<[/color][color=#0000ff]input[/color] [color=#ff0000]type[/color][color=#0000cc]=[/color][color=#ff0000]text[/color] [color=#ff0000]name[/color][color=#0000cc]=[/color]val[color=#0000cc]>[/color][color=#0000cc]<[/color][color=#0000ff]br[/color][color=#0000cc]>[/color]
指数[color=#0000cc]<[/color][color=#0000ff]input[/color] [color=#ff0000]type[/color][color=#0000cc]=[/color][color=#ff0000]text[/color] [color=#ff0000]name[/color][color=#0000cc]=[/color]power[color=#0000cc]>[/color][color=#0000cc]<[/color][color=#0000ff]br[/color][color=#0000cc]>[/color]
幂[color=#0000cc]<[/color][color=#0000ff]input[/color] [color=#ff0000]type[/color][color=#0000cc]=[/color][color=#ff0000]text[/color] [color=#ff0000]name[/color][color=#0000cc]=[/color]result[color=#0000cc]>[/color][color=#0000cc]<[/color][color=#0000ff]br[/color][color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000ff]input[/color] [color=#ff0000]type[/color][color=#0000cc]=[/color][color=#0000ff]button[/color] [color=#ff0000]name[/color][color=#0000cc]=[/color]button1 [color=#ff0000]value[/color][color=#0000cc]=[/color]计算结果 [color=#ff0000]onclick[/color][color=#0000cc]=[/color][color=#ff00ff]"document.form1.result.value=Math.pow (document.form1.val.value,document.form1.power.value)"[/color][color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000cc]/[/color][color=#0000ff]form[/color][color=#0000cc]>[/color]
6[color=#0000cc].[/color]发现最小值和最大值
[color=#0000cc]<[/color][color=#0000ff]form[/color] [color=#ff0000]name[/color][color=#0000cc]=[/color]form1[color=#0000cc]>[/color]
数字1[color=#0000cc]<[/color][color=#0000ff]input[/color] [color=#ff0000]type[/color][color=#0000cc]=[/color][color=#ff0000]text[/color] [color=#ff0000]name[/color][color=#0000cc]=[/color]val1[color=#0000cc]>[/color][color=#0000cc]<[/color][color=#0000ff]br[/color][color=#0000cc]>[/color]
数字2[color=#0000cc]<[/color][color=#0000ff]input[/color] [color=#ff0000]type[/color][color=#0000cc]=[/color][color=#ff0000]text[/color] [color=#ff0000]name[/color][color=#0000cc]=[/color]val2[color=#0000cc]>[/color][color=#0000cc]<[/color][color=#0000ff]br[/color][color=#0000cc]>[/color]
最小值[color=#0000cc]<[/color][color=#0000ff]input[/color] [color=#ff0000]type[/color][color=#0000cc]=[/color][color=#ff0000]text[/color] [color=#ff0000]name[/color][color=#0000cc]=[/color]min[color=#0000cc]>[/color][color=#0000cc]<[/color][color=#0000ff]br[/color][color=#0000cc]>[/color]
最大值[color=#0000cc]<[/color][color=#0000ff]input[/color] [color=#ff0000]type[/color][color=#0000cc]=[/color][color=#ff0000]text[/color] [color=#ff0000]name[/color][color=#0000cc]=[/color]max[color=#0000cc]>[/color][color=#0000cc]<[/color][color=#0000ff]br[/color][color=#0000cc]>[/color]
数字1[color=#0000cc]<[/color][color=#0000ff]input[/color] [color=#ff0000]type[/color][color=#0000cc]=[/color][color=#0000ff]button[/color] [color=#ff0000]value[/color][color=#0000cc]=[/color]计算 [color=#ff0000]onclick[/color][color=#0000cc]=[/color][color=#ff00ff]"document.form1.min.value=Math.min (document.form1.val1.value,document.form1.val2.value);document.form1.
max.value= Math.max(document.form1.val1.value,document.form1.val2.value)"[/color][color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000cc]/[/color][color=#0000ff]form[/color][color=#0000cc]>[/color]
[/color]
Nothing 2008-4-27 19:25
[color=#000000]第十二章 使用表单
1[color=#0000cc].[/color]使用文本框
2[color=#0000cc].[/color]使用密码框
[color=#0000cc]<[/color][color=#0000ff]form[/color] [color=#ff0000]name[/color][color=#0000cc]=[/color]form1[color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000ff]input[/color] [color=#ff0000]type[/color][color=#0000cc]=[/color]password [color=#ff0000]name[/color][color=#0000cc]=[/color]pw1 [color=#ff0000]value[/color][color=#0000cc]=[/color]daylight[color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000cc]/[/color][color=#0000ff]form[/color][color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000ff]script[/color][color=#0000cc]>[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color][color=#ff00ff]"表单pw1的类型:"[/color][color=#0000cc]+[/color]document[color=#0000cc].[/color]form1[color=#0000cc].[/color]pw1[color=#0000cc].[/color][color=#ff0000]type[/color][color=#0000cc]+[/color][color=#ff00ff]"<br>"[/color][color=#0000cc])[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color][color=#ff00ff]"表单pw1的名称:"[/color][color=#0000cc]+[/color]document[color=#0000cc].[/color]form1[color=#0000cc].[/color]pw1[color=#0000cc].[/color][color=#ff0000]name[/color][color=#0000cc]+[/color][color=#ff00ff]"<br>"[/color][color=#0000cc])[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color][color=#ff00ff]"表单pw1的值:"[/color][color=#0000cc]+[/color]document[color=#0000cc].[/color]form1[color=#0000cc].[/color]pw1[color=#0000cc].[/color][color=#ff0000]value[/color][color=#0000cc]+[/color][color=#ff00ff]"<br>"[/color][color=#0000cc])[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color][color=#ff00ff]"表单pw1的大小:"[/color][color=#0000cc]+[/color]document[color=#0000cc].[/color]form1[color=#0000cc].[/color]pw1[color=#0000cc].[/color][color=#ff0000]size[/color][color=#0000cc]+[/color][color=#ff00ff]"<br>"[/color][color=#0000cc])[/color]
[color=#0000cc]<[/color][color=#0000cc]/[/color][color=#0000ff]script[/color][color=#0000cc]>[/color]
3[color=#0000cc].[/color]使用隐藏字段
[color=#0000cc]<[/color][color=#0000ff]form[/color] [color=#ff0000]name[/color][color=#0000cc]=[/color]form1[color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000ff]input[/color] [color=#ff0000]type[/color][color=#0000cc]=[/color]hidden [color=#ff0000]name[/color][color=#0000cc]=[/color]hid1 [color=#ff0000]value[/color][color=#0000cc]=[/color]piece of eight[color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000cc]/[/color][color=#0000ff]form[/color][color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000ff]script[/color][color=#0000cc]>[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color][color=#ff00ff]"表单hid1的类型:"[/color][color=#0000cc]+[/color]document[color=#0000cc].[/color]form1[color=#0000cc].[/color]hid1[color=#0000cc].[/color][color=#ff0000]type[/color][color=#0000cc]+[/color][color=#ff00ff]"<br>"[/color][color=#0000cc])[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color][color=#ff00ff]"表单hid1的名称:"[/color][color=#0000cc]+[/color]document[color=#0000cc].[/color]form1[color=#0000cc].[/color]hid1[color=#0000cc].[/color][color=#ff0000]name[/color][color=#0000cc]+[/color][color=#ff00ff]"<br>"[/color][color=#0000cc])[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color][color=#ff00ff]"表单hid1的值:"[/color][color=#0000cc]+[/color]document[color=#0000cc].[/color]form1[color=#0000cc].[/color]hid1[color=#0000cc].[/color][color=#ff0000]value[/color][color=#0000cc]+[/color][color=#ff00ff]"<br>"[/color][color=#0000cc])[/color]
[color=#0000cc]<[/color][color=#0000cc]/[/color][color=#0000ff]script[/color][color=#0000cc]>[/color]
4[color=#0000cc].[/color]使用文本区域框
5[color=#0000cc].[/color]使用按钮
[color=#0000cc]<[/color][color=#0000ff]form[/color] [color=#ff0000]name[/color][color=#0000cc]=[/color]form1[color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000ff]input[/color] [color=#ff0000]type[/color][color=#0000cc]=[/color][color=#0000ff]button[/color] [color=#ff0000]name[/color][color=#0000cc]=[/color]button1 [color=#ff0000]value[/color][color=#0000cc]=[/color]标准按钮[color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000cc]/[/color][color=#0000ff]form[/color][color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000ff]script[/color][color=#0000cc]>[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color][color=#ff00ff]"表单button1的类型:"[/color][color=#0000cc]+[/color]document[color=#0000cc].[/color]form1[color=#0000cc].[/color]button1[color=#0000cc].[/color][color=#ff0000]type[/color][color=#0000cc]+[/color][color=#ff00ff]"<br>"[/color][color=#0000cc])[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color][color=#ff00ff]"表单button1的名称:"[/color][color=#0000cc]+[/color]document[color=#0000cc].[/color]form1[color=#0000cc].[/color]button1[color=#0000cc].[/color][color=#ff0000]name[/color][color=#0000cc]+[/color][color=#ff00ff]"<br>"[/color][color=#0000cc])[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color][color=#ff00ff]"表单button1的值:"[/color][color=#0000cc]+[/color]document[color=#0000cc].[/color]form1[color=#0000cc].[/color]button1[color=#0000cc].[/color][color=#ff0000]value[/color][color=#0000cc]+[/color][color=#ff00ff]"<br>"[/color][color=#0000cc])[/color]
[color=#0000cc]<[/color][color=#0000cc]/[/color][color=#0000ff]script[/color][color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000ff]form[/color] [color=#ff0000]name[/color][color=#0000cc]=[/color]form1[color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000ff]input[/color] [color=#ff0000]type[/color][color=#0000cc]=[/color][color=#ff0000]text[/color] [color=#ff0000]name[/color][color=#0000cc]=[/color]text1 [color=#ff0000]size[/color][color=#0000cc]=[/color]45[color=#0000cc]>[/color][color=#0000cc]<[/color][color=#0000ff]br[/color][color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000ff]input[/color] [color=#ff0000]type[/color][color=#0000cc]=[/color][color=#0000ff]button[/color] [color=#ff0000]name[/color][color=#0000cc]=[/color]button1 [color=#ff0000]value[/color][color=#0000cc]=[/color]panic [color=#0000ff]button[/color] [color=#ff0000]onclick[/color][color=#0000cc]=[/color][color=#ff00ff]"document.form1.text1.value='sittle down,count to 10 and take a deep breath'"[/color][color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000cc]/[/color][color=#0000ff]form[/color][color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000ff]form[/color] [color=#ff0000]name[/color][color=#0000cc]=[/color]form1[color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000ff]textarea[/color] [color=#ff0000]name[/color][color=#0000cc]=[/color]ta1[color=#0000cc]>[/color]how many grains of sand are there in the sahara desert?[color=#0000cc]<[/color][color=#0000cc]/[/color][color=#0000ff]textarea[/color][color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000cc]/[/color][color=#0000ff]form[/color][color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000ff]script[/color][color=#0000cc]>[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color][color=#ff00ff]"表单ta1的类型:"[/color][color=#0000cc]+[/color]document[color=#0000cc].[/color]form1[color=#0000cc].[/color]ta1[color=#0000cc].[/color][color=#ff0000]type[/color][color=#0000cc]+[/color][color=#ff00ff]"<br>"[/color][color=#0000cc])[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color][color=#ff00ff]"表单ta1的名称:"[/color][color=#0000cc]+[/color]document[color=#0000cc].[/color]form1[color=#0000cc].[/color]ta1[color=#0000cc].[/color][color=#ff0000]name[/color][color=#0000cc]+[/color][color=#ff00ff]"<br>"[/color][color=#0000cc])[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color][color=#ff00ff]"表单ta1的值:"[/color][color=#0000cc]+[/color]document[color=#0000cc].[/color]form1[color=#0000cc].[/color]ta1[color=#0000cc].[/color][color=#ff0000]value[/color][color=#0000cc]+[/color][color=#ff00ff]"<br>"[/color][color=#0000cc])[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color][color=#ff00ff]"表单ta1的横向宽度:"[/color][color=#0000cc]+[/color]document[color=#0000cc].[/color]form1[color=#0000cc].[/color]ta1[color=#0000cc].[/color][color=#ff0000]cols[/color][color=#0000cc]+[/color][color=#ff00ff]"<br>"[/color][color=#0000cc])[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color][color=#ff00ff]"表单ta1的纵向宽度:"[/color][color=#0000cc]+[/color]document[color=#0000cc].[/color]form1[color=#0000cc].[/color][color=#ff0000]rows[/color][color=#0000cc].[/color][color=#ff0000]value[/color][color=#0000cc]+[/color][color=#ff00ff]"<br>"[/color][color=#0000cc])[/color]
[color=#0000cc]<[/color][color=#0000cc]/[/color][color=#0000ff]script[/color][color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000ff]form[/color] [color=#ff0000]name[/color][color=#0000cc]=[/color]form1[color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000ff]textarea[/color] [color=#ff0000]name[/color][color=#0000cc]=[/color]ta1 [color=#ff0000]rows[/color][color=#0000cc]=[/color]4 [color=#ff0000]onfocus[/color][color=#0000cc]=[/color][color=#ff00ff]"document.form1.ta1.select()"[/color][color=#0000cc]>[/color] how many grains of sand are there in the sahara desert?[color=#0000cc]<[/color][color=#0000cc]/[/color][color=#0000ff]textarea[/color][color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000cc]/[/color][color=#0000ff]form[/color][color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000ff]form[/color] [color=#ff0000]name[/color][color=#0000cc]=[/color]form1[color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000ff]input[/color] [color=#ff0000]type[/color][color=#0000cc]=[/color][color=#ff0000]text[/color] [color=#ff0000]value[/color][color=#0000cc]=[/color][color=#ff00ff]"information ,please"[/color][color=#ff0000]name[/color][color=#0000cc]=[/color]text1[color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000cc]/[/color][color=#0000ff]form[/color][color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000ff]script[/color][color=#0000cc]>[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color][color=#ff00ff]"表单text1类型是: "[/color][color=#0000cc]+[/color]document[color=#0000cc].[/color]form1[color=#0000cc].[/color]text1[color=#0000cc].[/color][color=#ff0000]type[/color][color=#0000cc]+[/color][color=#ff00ff]"<br>"[/color][color=#0000cc])[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color][color=#ff00ff]"表单text1名称是: "[/color][color=#0000cc]+[/color]document[color=#0000cc].[/color]form1[color=#0000cc].[/color]text1[color=#0000cc].[/color][color=#ff0000]name[/color][color=#0000cc]+[/color][color=#ff00ff]"<br>"[/color][color=#0000cc])[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color][color=#ff00ff]"表单text1值是: "[/color][color=#0000cc]+[/color]document[color=#0000cc].[/color]form1[color=#0000cc].[/color]text1[color=#0000cc].[/color][color=#ff0000]value[/color][color=#0000cc]+[/color][color=#ff00ff]"<br>"[/color][color=#0000cc])[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color][color=#ff00ff]"表单text1大小是: "[/color][color=#0000cc]+[/color]document[color=#0000cc].[/color]form1[color=#0000cc].[/color]text1[color=#0000cc].[/color][color=#ff0000]size[/color][color=#0000cc]+[/color][color=#ff00ff]"<br>"[/color][color=#0000cc])[/color]
[color=#0000cc]<[/color][color=#0000cc]/[/color][color=#0000ff]script[/color][color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000ff]form[/color] [color=#ff0000]name[/color][color=#0000cc]=[/color]form1[color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000ff]input[/color] [color=#ff0000]type[/color][color=#0000cc]=[/color][color=#ff0000]text[/color] [color=#ff0000]name[/color][color=#0000cc]=[/color]text1 [color=#ff0000]value[/color][color=#0000cc]=[/color]click here
[color=#ff0000]onfocus[/color][color=#0000cc]=[/color]document[color=#0000cc].[/color]form1[color=#0000cc].[/color]text1[color=#0000cc].[/color][color=#0000ff]select[/color][color=#0000cc]([/color][color=#0000cc])[/color][color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000cc]/[/color][color=#0000ff]form[/color][color=#0000cc]>[/color]
6[color=#0000cc].[/color]使用重置按钮
[color=#0000cc]<[/color][color=#0000ff]form[/color] [color=#ff0000]name[/color][color=#0000cc]=[/color]form1[color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000ff]input[/color] [color=#ff0000]type[/color][color=#0000cc]=[/color]reset [color=#ff0000]name[/color][color=#0000cc]=[/color]reset1 [color=#ff0000]value[/color][color=#0000cc]=[/color][color=#ff00ff]"rest form"[/color][color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000cc]/[/color][color=#0000ff]form[/color][color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000ff]script[/color][color=#0000cc]>[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color][color=#ff00ff]"表单reset1的类型:"[/color][color=#0000cc]+[/color]document[color=#0000cc].[/color]form1[color=#0000cc].[/color]reset1[color=#0000cc].[/color][color=#ff0000]type[/color][color=#0000cc]+[/color][color=#ff00ff]"<br>"[/color][color=#0000cc])[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color][color=#ff00ff]"表单reset1的名称:"[/color][color=#0000cc]+[/color]document[color=#0000cc].[/color]form1[color=#0000cc].[/color]reset1[color=#0000cc].[/color][color=#ff0000]name[/color][color=#0000cc]+[/color][color=#ff00ff]"<br>"[/color][color=#0000cc])[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color][color=#ff00ff]"表单reset1的值:"[/color][color=#0000cc]+[/color]document[color=#0000cc].[/color]form1[color=#0000cc].[/color]reset1[color=#0000cc].[/color][color=#ff0000]value[/color][color=#0000cc]+[/color][color=#ff00ff]"<br>"[/color][color=#0000cc])[/color]
[color=#0000cc]<[/color][color=#0000cc]/[/color][color=#0000ff]script[/color][color=#0000cc]>[/color]
7[color=#0000cc].[/color]使用提交按钮
[color=#0000cc]<[/color][color=#0000ff]form[/color] [color=#ff0000]name[/color][color=#0000cc]=[/color]form1[color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000ff]input[/color] [color=#ff0000]type[/color][color=#0000cc]=[/color]submit [color=#ff0000]name[/color][color=#0000cc]=[/color]submit1 [color=#ff0000]value[/color][color=#0000cc]=[/color][color=#ff00ff]"submit form"[/color][color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000cc]/[/color][color=#0000ff]form[/color][color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000ff]script[/color][color=#0000cc]>[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color][color=#ff00ff]"表单submit1的类型:"[/color][color=#0000cc]+[/color]document[color=#0000cc].[/color]form1[color=#0000cc].[/color]submit1[color=#0000cc].[/color][color=#ff0000]type[/color][color=#0000cc]+[/color][color=#ff00ff]"<br>"[/color][color=#0000cc])[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color][color=#ff00ff]"表单submit1的名称:"[/color][color=#0000cc]+[/color]document[color=#0000cc].[/color]form1[color=#0000cc].[/color]submit1[color=#0000cc].[/color][color=#ff0000]name[/color][color=#0000cc]+[/color][color=#ff00ff]"<br>"[/color][color=#0000cc])[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color][color=#ff00ff]"表单submit1的值:"[/color][color=#0000cc]+[/color]document[color=#0000cc].[/color]form1[color=#0000cc].[/color]submit1[color=#0000cc].[/color][color=#ff0000]value[/color][color=#0000cc]+[/color][color=#ff00ff]"<br>"[/color][color=#0000cc])[/color]
[color=#0000cc]<[/color][color=#0000cc]/[/color][color=#0000ff]script[/color][color=#0000cc]>[/color]
8[color=#0000cc].[/color]使用复选按钮
[color=#0000cc]<[/color][color=#0000ff]form[/color] [color=#ff0000]name[/color][color=#0000cc]=[/color]form1[color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000ff]input[/color] [color=#ff0000]type[/color][color=#0000cc]=[/color]checkbox [color=#ff0000]name[/color][color=#0000cc]=[/color]cb1 [color=#0000cc]>[/color]computer savvy?
[color=#0000cc]<[/color][color=#0000cc]/[/color][color=#0000ff]form[/color][color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000ff]script[/color][color=#0000cc]>[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color][color=#ff00ff]"表单cb1的类型:"[/color][color=#0000cc]+[/color]document[color=#0000cc].[/color]form1[color=#0000cc].[/color]cb1[color=#0000cc].[/color][color=#ff0000]type[/color][color=#0000cc]+[/color][color=#ff00ff]"<br>"[/color][color=#0000cc])[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color][color=#ff00ff]"表单cb1是否被选择?:"[/color][color=#0000cc]+[/color]document[color=#0000cc].[/color]form1[color=#0000cc].[/color]cb1[color=#0000cc].[/color][color=#ff0000]checked[/color][color=#0000cc]+[/color][color=#ff00ff]"<br>"[/color][color=#0000cc])[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color][color=#ff00ff]"表单cb1的名称:"[/color][color=#0000cc]+[/color]document[color=#0000cc].[/color]form1[color=#0000cc].[/color]cb1[color=#0000cc].[/color][color=#ff0000]name[/color][color=#0000cc]+[/color][color=#ff00ff]"<br>"[/color][color=#0000cc])[/color]
[color=#0000cc]<[/color][color=#0000cc]/[/color][color=#0000ff]script[/color][color=#0000cc]>[/color]
9[color=#0000cc].[/color]使用单选按钮
[color=#0000cc]<[/color][color=#0000ff]form[/color] [color=#ff0000]name[/color][color=#0000cc]=[/color]form1[color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000ff]input[/color] [color=#ff0000]type[/color][color=#0000cc]=[/color]radio [color=#ff0000]name[/color][color=#0000cc]=[/color]radio1[color=#0000cc]>[/color]male
[color=#0000cc]<[/color][color=#0000ff]input[/color] [color=#ff0000]type[/color][color=#0000cc]=[/color]radio [color=#ff0000]name[/color][color=#0000cc]=[/color]radio1[color=#0000cc]>[/color]female
[color=#0000cc]<[/color][color=#0000cc]/[/color][color=#0000ff]form[/color][color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000ff]script[/color][color=#0000cc]>[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color][color=#ff00ff]"第一个按钮被选择"[/color][color=#0000cc]+[/color]document[color=#0000cc].[/color]form1[color=#0000cc].[/color]radio1[color=#0000cc][[/color]0[color=#0000cc]][/color][color=#0000cc].[/color][color=#ff0000]checked[/color][color=#0000cc]+[/color][color=#ff00ff]"<br>"[/color][color=#0000cc])[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color][color=#ff00ff]"第二个按钮被选择"[/color][color=#0000cc]+[/color]document[color=#0000cc].[/color]form1[color=#0000cc].[/color]radio1[color=#0000cc][[/color]1[color=#0000cc]][/color][color=#0000cc].[/color][color=#ff0000]checked[/color][color=#0000cc]+[/color][color=#ff00ff]"<br>"[/color][color=#0000cc])[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color][color=#ff00ff]"按钮的名称"[/color][color=#0000cc]+[/color] document[color=#0000cc].[/color]form1[color=#0000cc].[/color]radio1[color=#0000cc][[/color]0[color=#0000cc]][/color][color=#0000cc].[/color][color=#ff0000]name[/color][color=#0000cc]+[/color][color=#ff00ff]"<br>"[/color][color=#0000cc])[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color][color=#ff00ff]"按钮的个数"[/color][color=#0000cc]+[/color]document[color=#0000cc].[/color]form1[color=#0000cc].[/color]radio1[color=#0000cc].[/color]length[color=#0000cc])[/color]
[color=#0000cc]<[/color][color=#0000cc]/[/color][color=#0000ff]script[/color][color=#0000cc]>[/color]
10[color=#0000cc].[/color]使用选择列表
[color=#0000cc]<[/color][color=#0000ff]form[/color] [color=#ff0000]name[/color][color=#0000cc]=[/color]form1[color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000ff]select[/color] [color=#ff0000]name[/color][color=#0000cc]=[/color]select1 [color=#ff0000]size[/color][color=#0000cc]=[/color]4[color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000ff]option[/color] [color=#ff0000]name[/color][color=#0000cc]=[/color]option1 [color=#ff0000]value[/color][color=#0000cc]=[/color]lon[color=#0000cc]>[/color]london[color=#0000cc],[/color]England[color=#0000cc]<[/color][color=#0000cc]/[/color][color=#0000ff]option[/color][color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000ff]option[/color] [color=#ff0000]name[/color][color=#0000cc]=[/color]option2 [color=#ff0000]value[/color][color=#0000cc]=[/color]dub[color=#0000cc]>[/color]Dublin[color=#0000cc],[/color]Ireland[color=#0000cc]<[/color][color=#0000cc]/[/color][color=#0000ff]option[/color][color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000cc]/[/color][color=#0000ff]select[/color][color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000cc]/[/color][color=#0000ff]form[/color][color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000ff]script[/color][color=#0000cc]>[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color][color=#ff00ff]"这个选择列表的名称"[/color][color=#0000cc]+[/color]document[color=#0000cc].[/color]form1[color=#0000cc].[/color]select1[color=#0000cc].[/color][color=#ff0000]name[/color][color=#0000cc]+[/color][color=#ff00ff]"<br>"[/color][color=#0000cc])[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color][color=#ff00ff]"这个选择列表的长度"[/color][color=#0000cc]+[/color]document[color=#0000cc].[/color]form1[color=#0000cc].[/color]select1[color=#0000cc].[/color]length[color=#0000cc]+[/color][color=#ff00ff]"<br>"[/color][color=#0000cc])[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color][color=#ff00ff]"这个选择列表当前被选择的索引号"[/color][color=#0000cc]+[/color]document[color=#0000cc].[/color]form1[color=#0000cc].[/color]select1[color=#0000cc].[/color]selectedIndex[color=#0000cc]+[/color][color=#ff00ff]"<br>"[/color][color=#0000cc])[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color][color=#ff00ff]"这个选择列表的尺寸"[/color][color=#0000cc]+[/color]document[color=#0000cc].[/color]form1[color=#0000cc].[/color]select1[color=#0000cc].[/color][color=#ff0000]size[/color][color=#0000cc]+[/color][color=#ff00ff]"<br>"[/color][color=#0000cc])[/color]
[color=#0000cc]<[/color][color=#0000cc]/[/color][color=#0000ff]script[/color][color=#0000cc]>[/color]
11[color=#0000cc].[/color]验证表单的有效性
[color=#0000cc]<[/color][color=#0000ff]script[/color][color=#0000cc]>[/color]
function validate[color=#0000cc]([/color][color=#0000cc])[/color][color=#0000cc]{[/color]
if[color=#0000cc]([/color]document[color=#0000cc].[/color]form1[color=#0000cc].[/color]text1[color=#0000cc].[/color]value![color=#0000cc]=[/color][color=#ff00ff]'1'[/color][color=#0000cc]|[/color][color=#0000cc]|[/color][color=#ff00ff]'2'[/color][color=#0000cc]|[/color][color=#0000cc]|[/color][color=#ff00ff]'3'[/color][color=#0000cc]|[/color][color=#0000cc]|[/color][color=#ff00ff]'4'[/color][color=#0000cc])[/color][color=#0000cc]{[/color]
alert[color=#0000cc]([/color][color=#ff00ff]"请输入1~4的整数"[/color][color=#0000cc])[/color]
[color=#0000cc]}[/color]
[color=#0000cc]}[/color]
[color=#0000cc]<[/color][color=#0000cc]/[/color][color=#0000ff]script[/color][color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000ff]form[/color] [color=#ff0000]name[/color][color=#0000cc]=[/color]form1[color=#0000cc]>[/color]
请输入1[color=#0000cc]~[/color]4的整数:
[color=#0000cc]<[/color][color=#0000ff]input[/color] [color=#ff0000]type[/color][color=#0000cc]=[/color][color=#ff0000]text[/color] [color=#ff0000]name[/color][color=#0000cc]=[/color]text1 [color=#ff0000]size[/color][color=#0000cc]=[/color]4 [color=#ff0000]onchange[/color][color=#0000cc]=[/color]validate[color=#0000cc]([/color][color=#0000cc])[/color][color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000cc]/[/color][color=#0000ff]form[/color][color=#0000cc]>[/color]
12[color=#0000cc].[/color]控制表单焦点
[color=#0000cc]<[/color][color=#0000ff]form[/color] [color=#ff0000]name[/color][color=#0000cc]=[/color]form1[color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000ff]input[/color] [color=#ff0000]type[/color][color=#0000cc]=[/color][color=#ff0000]text[/color] [color=#ff0000]name[/color][color=#0000cc]=[/color]text1 [color=#ff0000]value[/color][color=#0000cc]=[/color]where is you focus?[color=#0000cc]>[/color][color=#0000cc]<[/color][color=#0000ff]br[/color][color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000ff]input[/color] [color=#ff0000]type[/color][color=#0000cc]=[/color][color=#ff0000]text[/color] [color=#ff0000]name[/color][color=#0000cc]=[/color]text2 [color=#ff0000]value[/color][color=#0000cc]=[/color]is there?[color=#0000cc]>[/color][color=#0000cc]<[/color][color=#0000ff]br[/color][color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000ff]input[/color] [color=#ff0000]type[/color][color=#0000cc]=[/color][color=#ff0000]text[/color] [color=#ff0000]name[/color][color=#0000cc]=[/color]text3 [color=#ff0000]value[/color][color=#0000cc]=[/color]or maybe here?[color=#0000cc]>[/color][color=#0000cc]<[/color][color=#0000ff]br[/color][color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000ff]input[/color] [color=#ff0000]type[/color][color=#0000cc]=[/color][color=#0000ff]button[/color] [color=#ff0000]name[/color][color=#0000cc]=[/color]button1 [color=#ff0000]value[/color][color=#0000cc]=[/color][color=#ff00ff]"text box #1"[/color] [color=#ff0000]onclick[/color][color=#0000cc]=[/color]document[color=#0000cc].[/color]form1[color=#0000cc].[/color]text1[color=#0000cc].[/color]focus[color=#0000cc]([/color][color=#0000cc])[/color][color=#0000cc]>[/color][color=#0000cc]<[/color][color=#0000ff]br[/color][color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000ff]input[/color] [color=#ff0000]type[/color][color=#0000cc]=[/color][color=#0000ff]button[/color] [color=#ff0000]name[/color][color=#0000cc]=[/color]button2 [color=#ff0000]value[/color][color=#0000cc]=[/color][color=#ff00ff]"text box #2"[/color] [color=#ff0000]onclick[/color][color=#0000cc]=[/color]document[color=#0000cc].[/color]form1[color=#0000cc].[/color]text2[color=#0000cc].[/color]focus[color=#0000cc]([/color][color=#0000cc])[/color][color=#0000cc]>[/color][color=#0000cc]<[/color][color=#0000ff]br[/color][color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000ff]input[/color] [color=#ff0000]type[/color][color=#0000cc]=[/color][color=#0000ff]button[/color] [color=#ff0000]name[/color][color=#0000cc]=[/color]button3 [color=#ff0000]value[/color][color=#0000cc]=[/color][color=#ff00ff]"text box #3"[/color] [color=#ff0000]onclick[/color][color=#0000cc]=[/color]document[color=#0000cc].[/color]form1[color=#0000cc].[/color]text3[color=#0000cc].[/color]focus[color=#0000cc]([/color][color=#0000cc])[/color][color=#0000cc]>[/color][color=#0000cc]<[/color][color=#0000ff]br[/color][color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000cc]/[/color][color=#0000ff]form[/color][color=#0000cc]>[/color] [/color]
Nothing 2008-4-27 19:25
[color=#000000]第十二章 使用表单
1[color=#0000cc].[/color]使用文本框
2[color=#0000cc].[/color]使用密码框
[color=#0000cc]<[/color][color=#0000ff]form[/color] [color=#ff0000]name[/color][color=#0000cc]=[/color]form1[color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000ff]input[/color] [color=#ff0000]type[/color][color=#0000cc]=[/color]password [color=#ff0000]name[/color][color=#0000cc]=[/color]pw1 [color=#ff0000]value[/color][color=#0000cc]=[/color]daylight[color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000cc]/[/color][color=#0000ff]form[/color][color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000ff]script[/color][color=#0000cc]>[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color][color=#ff00ff]"表单pw1的类型:"[/color][color=#0000cc]+[/color]document[color=#0000cc].[/color]form1[color=#0000cc].[/color]pw1[color=#0000cc].[/color][color=#ff0000]type[/color][color=#0000cc]+[/color][color=#ff00ff]"<br>"[/color][color=#0000cc])[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color][color=#ff00ff]"表单pw1的名称:"[/color][color=#0000cc]+[/color]document[color=#0000cc].[/color]form1[color=#0000cc].[/color]pw1[color=#0000cc].[/color][color=#ff0000]name[/color][color=#0000cc]+[/color][color=#ff00ff]"<br>"[/color][color=#0000cc])[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color][color=#ff00ff]"表单pw1的值:"[/color][color=#0000cc]+[/color]document[color=#0000cc].[/color]form1[color=#0000cc].[/color]pw1[color=#0000cc].[/color][color=#ff0000]value[/color][color=#0000cc]+[/color][color=#ff00ff]"<br>"[/color][color=#0000cc])[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color][color=#ff00ff]"表单pw1的大小:"[/color][color=#0000cc]+[/color]document[color=#0000cc].[/color]form1[color=#0000cc].[/color]pw1[color=#0000cc].[/color][color=#ff0000]size[/color][color=#0000cc]+[/color][color=#ff00ff]"<br>"[/color][color=#0000cc])[/color]
[color=#0000cc]<[/color][color=#0000cc]/[/color][color=#0000ff]script[/color][color=#0000cc]>[/color]
3[color=#0000cc].[/color]使用隐藏字段
[color=#0000cc]<[/color][color=#0000ff]form[/color] [color=#ff0000]name[/color][color=#0000cc]=[/color]form1[color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000ff]input[/color] [color=#ff0000]type[/color][color=#0000cc]=[/color]hidden [color=#ff0000]name[/color][color=#0000cc]=[/color]hid1 [color=#ff0000]value[/color][color=#0000cc]=[/color]piece of eight[color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000cc]/[/color][color=#0000ff]form[/color][color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000ff]script[/color][color=#0000cc]>[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color][color=#ff00ff]"表单hid1的类型:"[/color][color=#0000cc]+[/color]document[color=#0000cc].[/color]form1[color=#0000cc].[/color]hid1[color=#0000cc].[/color][color=#ff0000]type[/color][color=#0000cc]+[/color][color=#ff00ff]"<br>"[/color][color=#0000cc])[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color][color=#ff00ff]"表单hid1的名称:"[/color][color=#0000cc]+[/color]document[color=#0000cc].[/color]form1[color=#0000cc].[/color]hid1[color=#0000cc].[/color][color=#ff0000]name[/color][color=#0000cc]+[/color][color=#ff00ff]"<br>"[/color][color=#0000cc])[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color][color=#ff00ff]"表单hid1的值:"[/color][color=#0000cc]+[/color]document[color=#0000cc].[/color]form1[color=#0000cc].[/color]hid1[color=#0000cc].[/color][color=#ff0000]value[/color][color=#0000cc]+[/color][color=#ff00ff]"<br>"[/color][color=#0000cc])[/color]
[color=#0000cc]<[/color][color=#0000cc]/[/color][color=#0000ff]script[/color][color=#0000cc]>[/color]
4[color=#0000cc].[/color]使用文本区域框
5[color=#0000cc].[/color]使用按钮
[color=#0000cc]<[/color][color=#0000ff]form[/color] [color=#ff0000]name[/color][color=#0000cc]=[/color]form1[color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000ff]input[/color] [color=#ff0000]type[/color][color=#0000cc]=[/color][color=#0000ff]button[/color] [color=#ff0000]name[/color][color=#0000cc]=[/color]button1 [color=#ff0000]value[/color][color=#0000cc]=[/color]标准按钮[color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000cc]/[/color][color=#0000ff]form[/color][color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000ff]script[/color][color=#0000cc]>[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color][color=#ff00ff]"表单button1的类型:"[/color][color=#0000cc]+[/color]document[color=#0000cc].[/color]form1[color=#0000cc].[/color]button1[color=#0000cc].[/color][color=#ff0000]type[/color][color=#0000cc]+[/color][color=#ff00ff]"<br>"[/color][color=#0000cc])[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color][color=#ff00ff]"表单button1的名称:"[/color][color=#0000cc]+[/color]document[color=#0000cc].[/color]form1[color=#0000cc].[/color]button1[color=#0000cc].[/color][color=#ff0000]name[/color][color=#0000cc]+[/color][color=#ff00ff]"<br>"[/color][color=#0000cc])[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color][color=#ff00ff]"表单button1的值:"[/color][color=#0000cc]+[/color]document[color=#0000cc].[/color]form1[color=#0000cc].[/color]button1[color=#0000cc].[/color][color=#ff0000]value[/color][color=#0000cc]+[/color][color=#ff00ff]"<br>"[/color][color=#0000cc])[/color]
[color=#0000cc]<[/color][color=#0000cc]/[/color][color=#0000ff]script[/color][color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000ff]form[/color] [color=#ff0000]name[/color][color=#0000cc]=[/color]form1[color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000ff]input[/color] [color=#ff0000]type[/color][color=#0000cc]=[/color][color=#ff0000]text[/color] [color=#ff0000]name[/color][color=#0000cc]=[/color]text1 [color=#ff0000]size[/color][color=#0000cc]=[/color]45[color=#0000cc]>[/color][color=#0000cc]<[/color][color=#0000ff]br[/color][color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000ff]input[/color] [color=#ff0000]type[/color][color=#0000cc]=[/color][color=#0000ff]button[/color] [color=#ff0000]name[/color][color=#0000cc]=[/color]button1 [color=#ff0000]value[/color][color=#0000cc]=[/color]panic [color=#0000ff]button[/color] [color=#ff0000]onclick[/color][color=#0000cc]=[/color][color=#ff00ff]"document.form1.text1.value='sittle down,count to 10 and take a deep breath'"[/color][color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000cc]/[/color][color=#0000ff]form[/color][color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000ff]form[/color] [color=#ff0000]name[/color][color=#0000cc]=[/color]form1[color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000ff]textarea[/color] [color=#ff0000]name[/color][color=#0000cc]=[/color]ta1[color=#0000cc]>[/color]how many grains of sand are there in the sahara desert?[color=#0000cc]<[/color][color=#0000cc]/[/color][color=#0000ff]textarea[/color][color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000cc]/[/color][color=#0000ff]form[/color][color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000ff]script[/color][color=#0000cc]>[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color][color=#ff00ff]"表单ta1的类型:"[/color][color=#0000cc]+[/color]document[color=#0000cc].[/color]form1[color=#0000cc].[/color]ta1[color=#0000cc].[/color][color=#ff0000]type[/color][color=#0000cc]+[/color][color=#ff00ff]"<br>"[/color][color=#0000cc])[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color][color=#ff00ff]"表单ta1的名称:"[/color][color=#0000cc]+[/color]document[color=#0000cc].[/color]form1[color=#0000cc].[/color]ta1[color=#0000cc].[/color][color=#ff0000]name[/color][color=#0000cc]+[/color][color=#ff00ff]"<br>"[/color][color=#0000cc])[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color][color=#ff00ff]"表单ta1的值:"[/color][color=#0000cc]+[/color]document[color=#0000cc].[/color]form1[color=#0000cc].[/color]ta1[color=#0000cc].[/color][color=#ff0000]value[/color][color=#0000cc]+[/color][color=#ff00ff]"<br>"[/color][color=#0000cc])[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color][color=#ff00ff]"表单ta1的横向宽度:"[/color][color=#0000cc]+[/color]document[color=#0000cc].[/color]form1[color=#0000cc].[/color]ta1[color=#0000cc].[/color][color=#ff0000]cols[/color][color=#0000cc]+[/color][color=#ff00ff]"<br>"[/color][color=#0000cc])[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color][color=#ff00ff]"表单ta1的纵向宽度:"[/color][color=#0000cc]+[/color]document[color=#0000cc].[/color]form1[color=#0000cc].[/color][color=#ff0000]rows[/color][color=#0000cc].[/color][color=#ff0000]value[/color][color=#0000cc]+[/color][color=#ff00ff]"<br>"[/color][color=#0000cc])[/color]
[color=#0000cc]<[/color][color=#0000cc]/[/color][color=#0000ff]script[/color][color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000ff]form[/color] [color=#ff0000]name[/color][color=#0000cc]=[/color]form1[color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000ff]textarea[/color] [color=#ff0000]name[/color][color=#0000cc]=[/color]ta1 [color=#ff0000]rows[/color][color=#0000cc]=[/color]4 [color=#ff0000]onfocus[/color][color=#0000cc]=[/color][color=#ff00ff]"document.form1.ta1.select()"[/color][color=#0000cc]>[/color] how many grains of sand are there in the sahara desert?[color=#0000cc]<[/color][color=#0000cc]/[/color][color=#0000ff]textarea[/color][color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000cc]/[/color][color=#0000ff]form[/color][color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000ff]form[/color] [color=#ff0000]name[/color][color=#0000cc]=[/color]form1[color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000ff]input[/color] [color=#ff0000]type[/color][color=#0000cc]=[/color][color=#ff0000]text[/color] [color=#ff0000]value[/color][color=#0000cc]=[/color][color=#ff00ff]"information ,please"[/color][color=#ff0000]name[/color][color=#0000cc]=[/color]text1[color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000cc]/[/color][color=#0000ff]form[/color][color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000ff]script[/color][color=#0000cc]>[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color][color=#ff00ff]"表单text1类型是: "[/color][color=#0000cc]+[/color]document[color=#0000cc].[/color]form1[color=#0000cc].[/color]text1[color=#0000cc].[/color][color=#ff0000]type[/color][color=#0000cc]+[/color][color=#ff00ff]"<br>"[/color][color=#0000cc])[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color][color=#ff00ff]"表单text1名称是: "[/color][color=#0000cc]+[/color]document[color=#0000cc].[/color]form1[color=#0000cc].[/color]text1[color=#0000cc].[/color][color=#ff0000]name[/color][color=#0000cc]+[/color][color=#ff00ff]"<br>"[/color][color=#0000cc])[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color][color=#ff00ff]"表单text1值是: "[/color][color=#0000cc]+[/color]document[color=#0000cc].[/color]form1[color=#0000cc].[/color]text1[color=#0000cc].[/color][color=#ff0000]value[/color][color=#0000cc]+[/color][color=#ff00ff]"<br>"[/color][color=#0000cc])[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color][color=#ff00ff]"表单text1大小是: "[/color][color=#0000cc]+[/color]document[color=#0000cc].[/color]form1[color=#0000cc].[/color]text1[color=#0000cc].[/color][color=#ff0000]size[/color][color=#0000cc]+[/color][color=#ff00ff]"<br>"[/color][color=#0000cc])[/color]
[color=#0000cc]<[/color][color=#0000cc]/[/color][color=#0000ff]script[/color][color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000ff]form[/color] [color=#ff0000]name[/color][color=#0000cc]=[/color]form1[color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000ff]input[/color] [color=#ff0000]type[/color][color=#0000cc]=[/color][color=#ff0000]text[/color] [color=#ff0000]name[/color][color=#0000cc]=[/color]text1 [color=#ff0000]value[/color][color=#0000cc]=[/color]click here
[color=#ff0000]onfocus[/color][color=#0000cc]=[/color]document[color=#0000cc].[/color]form1[color=#0000cc].[/color]text1[color=#0000cc].[/color][color=#0000ff]select[/color][color=#0000cc]([/color][color=#0000cc])[/color][color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000cc]/[/color][color=#0000ff]form[/color][color=#0000cc]>[/color]
6[color=#0000cc].[/color]使用重置按钮
[color=#0000cc]<[/color][color=#0000ff]form[/color] [color=#ff0000]name[/color][color=#0000cc]=[/color]form1[color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000ff]input[/color] [color=#ff0000]type[/color][color=#0000cc]=[/color]reset [color=#ff0000]name[/color][color=#0000cc]=[/color]reset1 [color=#ff0000]value[/color][color=#0000cc]=[/color][color=#ff00ff]"rest form"[/color][color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000cc]/[/color][color=#0000ff]form[/color][color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000ff]script[/color][color=#0000cc]>[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color][color=#ff00ff]"表单reset1的类型:"[/color][color=#0000cc]+[/color]document[color=#0000cc].[/color]form1[color=#0000cc].[/color]reset1[color=#0000cc].[/color][color=#ff0000]type[/color][color=#0000cc]+[/color][color=#ff00ff]"<br>"[/color][color=#0000cc])[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color][color=#ff00ff]"表单reset1的名称:"[/color][color=#0000cc]+[/color]document[color=#0000cc].[/color]form1[color=#0000cc].[/color]reset1[color=#0000cc].[/color][color=#ff0000]name[/color][color=#0000cc]+[/color][color=#ff00ff]"<br>"[/color][color=#0000cc])[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color][color=#ff00ff]"表单reset1的值:"[/color][color=#0000cc]+[/color]document[color=#0000cc].[/color]form1[color=#0000cc].[/color]reset1[color=#0000cc].[/color][color=#ff0000]value[/color][color=#0000cc]+[/color][color=#ff00ff]"<br>"[/color][color=#0000cc])[/color]
[color=#0000cc]<[/color][color=#0000cc]/[/color][color=#0000ff]script[/color][color=#0000cc]>[/color]
7[color=#0000cc].[/color]使用提交按钮
[color=#0000cc]<[/color][color=#0000ff]form[/color] [color=#ff0000]name[/color][color=#0000cc]=[/color]form1[color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000ff]input[/color] [color=#ff0000]type[/color][color=#0000cc]=[/color]submit [color=#ff0000]name[/color][color=#0000cc]=[/color]submit1 [color=#ff0000]value[/color][color=#0000cc]=[/color][color=#ff00ff]"submit form"[/color][color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000cc]/[/color][color=#0000ff]form[/color][color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000ff]script[/color][color=#0000cc]>[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color][color=#ff00ff]"表单submit1的类型:"[/color][color=#0000cc]+[/color]document[color=#0000cc].[/color]form1[color=#0000cc].[/color]submit1[color=#0000cc].[/color][color=#ff0000]type[/color][color=#0000cc]+[/color][color=#ff00ff]"<br>"[/color][color=#0000cc])[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color][color=#ff00ff]"表单submit1的名称:"[/color][color=#0000cc]+[/color]document[color=#0000cc].[/color]form1[color=#0000cc].[/color]submit1[color=#0000cc].[/color][color=#ff0000]name[/color][color=#0000cc]+[/color][color=#ff00ff]"<br>"[/color][color=#0000cc])[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color][color=#ff00ff]"表单submit1的值:"[/color][color=#0000cc]+[/color]document[color=#0000cc].[/color]form1[color=#0000cc].[/color]submit1[color=#0000cc].[/color][color=#ff0000]value[/color][color=#0000cc]+[/color][color=#ff00ff]"<br>"[/color][color=#0000cc])[/color]
[color=#0000cc]<[/color][color=#0000cc]/[/color][color=#0000ff]script[/color][color=#0000cc]>[/color]
8[color=#0000cc].[/color]使用复选按钮
[color=#0000cc]<[/color][color=#0000ff]form[/color] [color=#ff0000]name[/color][color=#0000cc]=[/color]form1[color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000ff]input[/color] [color=#ff0000]type[/color][color=#0000cc]=[/color]checkbox [color=#ff0000]name[/color][color=#0000cc]=[/color]cb1 [color=#0000cc]>[/color]computer savvy?
[color=#0000cc]<[/color][color=#0000cc]/[/color][color=#0000ff]form[/color][color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000ff]script[/color][color=#0000cc]>[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color][color=#ff00ff]"表单cb1的类型:"[/color][color=#0000cc]+[/color]document[color=#0000cc].[/color]form1[color=#0000cc].[/color]cb1[color=#0000cc].[/color][color=#ff0000]type[/color][color=#0000cc]+[/color][color=#ff00ff]"<br>"[/color][color=#0000cc])[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color][color=#ff00ff]"表单cb1是否被选择?:"[/color][color=#0000cc]+[/color]document[color=#0000cc].[/color]form1[color=#0000cc].[/color]cb1[color=#0000cc].[/color][color=#ff0000]checked[/color][color=#0000cc]+[/color][color=#ff00ff]"<br>"[/color][color=#0000cc])[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color][color=#ff00ff]"表单cb1的名称:"[/color][color=#0000cc]+[/color]document[color=#0000cc].[/color]form1[color=#0000cc].[/color]cb1[color=#0000cc].[/color][color=#ff0000]name[/color][color=#0000cc]+[/color][color=#ff00ff]"<br>"[/color][color=#0000cc])[/color]
[color=#0000cc]<[/color][color=#0000cc]/[/color][color=#0000ff]script[/color][color=#0000cc]>[/color]
9[color=#0000cc].[/color]使用单选按钮
[color=#0000cc]<[/color][color=#0000ff]form[/color] [color=#ff0000]name[/color][color=#0000cc]=[/color]form1[color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000ff]input[/color] [color=#ff0000]type[/color][color=#0000cc]=[/color]radio [color=#ff0000]name[/color][color=#0000cc]=[/color]radio1[color=#0000cc]>[/color]male
[color=#0000cc]<[/color][color=#0000ff]input[/color] [color=#ff0000]type[/color][color=#0000cc]=[/color]radio [color=#ff0000]name[/color][color=#0000cc]=[/color]radio1[color=#0000cc]>[/color]female
[color=#0000cc]<[/color][color=#0000cc]/[/color][color=#0000ff]form[/color][color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000ff]script[/color][color=#0000cc]>[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color][color=#ff00ff]"第一个按钮被选择"[/color][color=#0000cc]+[/color]document[color=#0000cc].[/color]form1[color=#0000cc].[/color]radio1[color=#0000cc][[/color]0[color=#0000cc]][/color][color=#0000cc].[/color][color=#ff0000]checked[/color][color=#0000cc]+[/color][color=#ff00ff]"<br>"[/color][color=#0000cc])[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color][color=#ff00ff]"第二个按钮被选择"[/color][color=#0000cc]+[/color]document[color=#0000cc].[/color]form1[color=#0000cc].[/color]radio1[color=#0000cc][[/color]1[color=#0000cc]][/color][color=#0000cc].[/color][color=#ff0000]checked[/color][color=#0000cc]+[/color][color=#ff00ff]"<br>"[/color][color=#0000cc])[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color][color=#ff00ff]"按钮的名称"[/color][color=#0000cc]+[/color] document[color=#0000cc].[/color]form1[color=#0000cc].[/color]radio1[color=#0000cc][[/color]0[color=#0000cc]][/color][color=#0000cc].[/color][color=#ff0000]name[/color][color=#0000cc]+[/color][color=#ff00ff]"<br>"[/color][color=#0000cc])[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color][color=#ff00ff]"按钮的个数"[/color][color=#0000cc]+[/color]document[color=#0000cc].[/color]form1[color=#0000cc].[/color]radio1[color=#0000cc].[/color]length[color=#0000cc])[/color]
[color=#0000cc]<[/color][color=#0000cc]/[/color][color=#0000ff]script[/color][color=#0000cc]>[/color]
10[color=#0000cc].[/color]使用选择列表
[color=#0000cc]<[/color][color=#0000ff]form[/color] [color=#ff0000]name[/color][color=#0000cc]=[/color]form1[color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000ff]select[/color] [color=#ff0000]name[/color][color=#0000cc]=[/color]select1 [color=#ff0000]size[/color][color=#0000cc]=[/color]4[color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000ff]option[/color] [color=#ff0000]name[/color][color=#0000cc]=[/color]option1 [color=#ff0000]value[/color][color=#0000cc]=[/color]lon[color=#0000cc]>[/color]london[color=#0000cc],[/color]England[color=#0000cc]<[/color][color=#0000cc]/[/color][color=#0000ff]option[/color][color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000ff]option[/color] [color=#ff0000]name[/color][color=#0000cc]=[/color]option2 [color=#ff0000]value[/color][color=#0000cc]=[/color]dub[color=#0000cc]>[/color]Dublin[color=#0000cc],[/color]Ireland[color=#0000cc]<[/color][color=#0000cc]/[/color][color=#0000ff]option[/color][color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000cc]/[/color][color=#0000ff]select[/color][color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000cc]/[/color][color=#0000ff]form[/color][color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000ff]script[/color][color=#0000cc]>[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color][color=#ff00ff]"这个选择列表的名称"[/color][color=#0000cc]+[/color]document[color=#0000cc].[/color]form1[color=#0000cc].[/color]select1[color=#0000cc].[/color][color=#ff0000]name[/color][color=#0000cc]+[/color][color=#ff00ff]"<br>"[/color][color=#0000cc])[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color][color=#ff00ff]"这个选择列表的长度"[/color][color=#0000cc]+[/color]document[color=#0000cc].[/color]form1[color=#0000cc].[/color]select1[color=#0000cc].[/color]length[color=#0000cc]+[/color][color=#ff00ff]"<br>"[/color][color=#0000cc])[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color][color=#ff00ff]"这个选择列表当前被选择的索引号"[/color][color=#0000cc]+[/color]document[color=#0000cc].[/color]form1[color=#0000cc].[/color]select1[color=#0000cc].[/color]selectedIndex[color=#0000cc]+[/color][color=#ff00ff]"<br>"[/color][color=#0000cc])[/color]
document[color=#0000cc].[/color]write[color=#0000cc]([/color][color=#ff00ff]"这个选择列表的尺寸"[/color][color=#0000cc]+[/color]document[color=#0000cc].[/color]form1[color=#0000cc].[/color]select1[color=#0000cc].[/color][color=#ff0000]size[/color][color=#0000cc]+[/color][color=#ff00ff]"<br>"[/color][color=#0000cc])[/color]
[color=#0000cc]<[/color][color=#0000cc]/[/color][color=#0000ff]script[/color][color=#0000cc]>[/color]
11[color=#0000cc].[/color]验证表单的有效性
[color=#0000cc]<[/color][color=#0000ff]script[/color][color=#0000cc]>[/color]
function validate[color=#0000cc]([/color][color=#0000cc])[/color][color=#0000cc]{[/color]
if[color=#0000cc]([/color]document[color=#0000cc].[/color]form1[color=#0000cc].[/color]text1[color=#0000cc].[/color]value![color=#0000cc]=[/color][color=#ff00ff]'1'[/color][color=#0000cc]|[/color][color=#0000cc]|[/color][color=#ff00ff]'2'[/color][color=#0000cc]|[/color][color=#0000cc]|[/color][color=#ff00ff]'3'[/color][color=#0000cc]|[/color][color=#0000cc]|[/color][color=#ff00ff]'4'[/color][color=#0000cc])[/color][color=#0000cc]{[/color]
alert[color=#0000cc]([/color][color=#ff00ff]"请输入1~4的整数"[/color][color=#0000cc])[/color]
[color=#0000cc]}[/color]
[color=#0000cc]}[/color]
[color=#0000cc]<[/color][color=#0000cc]/[/color][color=#0000ff]script[/color][color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000ff]form[/color] [color=#ff0000]name[/color][color=#0000cc]=[/color]form1[color=#0000cc]>[/color]
请输入1[color=#0000cc]~[/color]4的整数:
[color=#0000cc]<[/color][color=#0000ff]input[/color] [color=#ff0000]type[/color][color=#0000cc]=[/color][color=#ff0000]text[/color] [color=#ff0000]name[/color][color=#0000cc]=[/color]text1 [color=#ff0000]size[/color][color=#0000cc]=[/color]4 [color=#ff0000]onchange[/color][color=#0000cc]=[/color]validate[color=#0000cc]([/color][color=#0000cc])[/color][color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000cc]/[/color][color=#0000ff]form[/color][color=#0000cc]>[/color]
12[color=#0000cc].[/color]控制表单焦点
[color=#0000cc]<[/color][color=#0000ff]form[/color] [color=#ff0000]name[/color][color=#0000cc]=[/color]form1[color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000ff]input[/color] [color=#ff0000]type[/color][color=#0000cc]=[/color][color=#ff0000]text[/color] [color=#ff0000]name[/color][color=#0000cc]=[/color]text1 [color=#ff0000]value[/color][color=#0000cc]=[/color]where is you focus?[color=#0000cc]>[/color][color=#0000cc]<[/color][color=#0000ff]br[/color][color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000ff]input[/color] [color=#ff0000]type[/color][color=#0000cc]=[/color][color=#ff0000]text[/color] [color=#ff0000]name[/color][color=#0000cc]=[/color]text2 [color=#ff0000]value[/color][color=#0000cc]=[/color]is there?[color=#0000cc]>[/color][color=#0000cc]<[/color][color=#0000ff]br[/color][color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000ff]input[/color] [color=#ff0000]type[/color][color=#0000cc]=[/color][color=#ff0000]text[/color] [color=#ff0000]name[/color][color=#0000cc]=[/color]text3 [color=#ff0000]value[/color][color=#0000cc]=[/color]or maybe here?[color=#0000cc]>[/color][color=#0000cc]<[/color][color=#0000ff]br[/color][color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000ff]input[/color] [color=#ff0000]type[/color][color=#0000cc]=[/color][color=#0000ff]button[/color] [color=#ff0000]name[/color][color=#0000cc]=[/color]button1 [color=#ff0000]value[/color][color=#0000cc]=[/color][color=#ff00ff]"text box #1"[/color] [color=#ff0000]onclick[/color][color=#0000cc]=[/color]document[color=#0000cc].[/color]form1[color=#0000cc].[/color]text1[color=#0000cc].[/color]focus[color=#0000cc]([/color][color=#0000cc])[/color][color=#0000cc]>[/color][color=#0000cc]<[/color][color=#0000ff]br[/color][color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000ff]input[/color] [color=#ff0000]type[/color][color=#0000cc]=[/color][color=#0000ff]button[/color] [color=#ff0000]name[/color][color=#0000cc]=[/color]button2 [color=#ff0000]value[/color][color=#0000cc]=[/color][color=#ff00ff]"text box #2"[/color] [color=#ff0000]onclick[/color][color=#0000cc]=[/color]document[color=#0000cc].[/color]form1[color=#0000cc].[/color]text2[color=#0000cc].[/color]focus[color=#0000cc]([/color][color=#0000cc])[/color][color=#0000cc]>[/color][color=#0000cc]<[/color][color=#0000ff]br[/color][color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000ff]input[/color] [color=#ff0000]type[/color][color=#0000cc]=[/color][color=#0000ff]button[/color] [color=#ff0000]name[/color][color=#0000cc]=[/color]button3 [color=#ff0000]value[/color][color=#0000cc]=[/color][color=#ff00ff]"text box #3"[/color] [color=#ff0000]onclick[/color][color=#0000cc]=[/color]document[color=#0000cc].[/color]form1[color=#0000cc].[/color]text3[color=#0000cc].[/color]focus[color=#0000cc]([/color][color=#0000cc])[/color][color=#0000cc]>[/color][color=#0000cc]<[/color][color=#0000ff]br[/color][color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000cc]/[/color][color=#0000ff]form[/color][color=#0000cc]>[/color] [/color]
黑发的放牧者 2008-5-27 14:31
很实用
偶补充点儿。
关联数组
var assocArray = newObject();
assocArray["one"] = "one";
assocArray["two"] = "two";
页:
[1]