首頁 > web前端 > js教程 > 清华大学出版的事半功倍系列 javascript全部源代码_javascript技巧

清华大学出版的事半功倍系列 javascript全部源代码_javascript技巧

WBOY
發布: 2016-05-16 19:14:02
原創
1173 人瀏覽過

清华大学出版的】,本人照着书敲出来的,有些翻译了一下.前几年看了一下,最近无事,重新翻了翻,很有帮助.本书应该有光盘的,但学校的书,光盘不知在哪.希望对你学 javascript有帮助

第一章javascript简介
1.在地址栏输入javascript语句
Javascript:Document.write("显示文字")
2.将javascript嵌入 HTML文档
<script> <BR>document.bgColor="blue" <BR></script>
第二章 使用变量和数组
1.声明变量
<script> <BR>Var answer1,answer2,answer3,answer4; <BR>answer1=9; <BR>answer2=2.5 <BR>answer3="Milkey May" <BR>answer4=true <BR></script>
2.使用整数
<script> <BR>var decimalNum,hexadecimalNum,octalNum <BR>decimalNum=24 <BR>hexadecimalNum=0x24 <BR>octalNum=024 <BR>document.write("显示十进制数:"+ decimalNum+"<br>") <BR>document.write("显示十六进制数:"+ hexadecimalNum +"<br>") <BR>document.write("显示八进制数:"+ octalNum +"<br>") <BR></script>
3.使用浮点数
<script> <BR>var num1,num2,num3,num4 <BR>num1=1234567890000.0 <BR>num2=5.14e23 <BR>num3=0.0000123456 <BR>num4=6.0254e3-4 <BR>document.write("浮点数1:"+num1+"<br>") <BR>document.write("浮点数2:"+num2+"<br>") <BR>document.write("浮点数3:"+num3+"<br>") <BR>document.write("浮点数4:"+num4+"<br>") <BR></script>
4.使用布尔值
<script> <BR>var answer1,answer2 <BR>answer1=true <BR>answer2=false <BR>document.write("显示布尔1:"+answer1+"<br>") <BR>document.write("显示布尔2:"+answer2+"<br>") <BR></script>
5.使用字符串
<script> <BR>var str1,str2 <BR>str1="fdsgdg dsfdsf china" <BR>str2="武汉市广播电视大学" <BR>document.write("显示字符串1:"+str1+"<br>") <BR>document.write("显示字符串2:"+str2+"<br>") <BR></script>
6.确定变量类型
<script> <BR>var answer1,answer2,answer3,answer4 <BR>answer1=9 <BR>answer2=2.5 <BR>answer3="milky may" <BR>answer4=true <BR>document.write("变量1的类型是:"+typeof answer1 +"<br>") <BR>document.write("变量2的类型是:"+typeof answer2 +"<br>") <BR>document.write("变量3的类型是:"+typeof answer3 +"<br>") <BR>document.write("变量4的类型是:"+typeof answer4 +"<br>") <BR></script>
7.将字符串转换成数字
<script> <BR>var str1="31 days in january" <BR>var int1=parseInt(str1) <BR>document.write("str1的数据类型是 :"+typeof str1+"<br>") <BR>document.write("int1的数据类型是 :"+typeof int1+"<br>") <BR></script>
8.将数字转换成字符串
<script> <BR>var int1=256 <BR>var str1=""+int1 <BR>document.write("str1的数据类型是 :"+typeof str1+"<br>") <BR>document.write("int1的数据类型是 :"+typeof int1+"<br>") <BR></script>
9.声明数组
<script> <BR>array=new Array(5) <BR>array[0]=1 <BR>array[1]=3 <BR>array[2]=5 <BR>array[3]=7 <BR>array[4]=11 <BR>document.write("数组是:"+array[0]+" "+array[1]+" "+array[2]+" "+array[3]+" "+array[4]) <BR></script>
10.确定数组元素的个数
<script> <BR>array=new Array(5) <BR>array[0]=1 <BR>array[1]=3 <BR>array[2]=5 <BR>array[3]=7 <BR>array[4]=11 <BR>document.write("数组是:"+array[0]+" "+array[1]+" "+array[2]+" "+array[3]+" "+array[4]+"<br>") <BR>document.write("数组的元素个数是"+array.length) <BR></script>
11.将数组转换为字符串
<script> <BR>array=new Array() <BR>array[0]="dark" <BR>array[1]="apple" <BR>array[2]="nebula" <BR>array[3]="water" <BR>str1=array.join() <BR>str2=array.join(" ") <BR>document.write(str1+"<br>") <BR>document.write(str2) <BR></script>
12.对数组排序
<script> <BR>array=new Array() <BR>array[0]="dark" <BR>array[1]="apple" <BR>array[2]="nebula" <BR>array[3]="water" <BR>str1=array.sort() <BR>document.write(str1+"<br>") <BR></script>
第三章 创建表达式
1.使用算术运算符
<script> <BR>var1=12 <BR>var2=10 <BR>varadd=var1+var2 <BR>varsub=var1-var2 <BR>varmult=var1*var2 <BR>vardiv=var1/var2 <BR>varmod=var1%var2 <BR>document.write("数据1是:"+var1+"<br>") <BR>document.write("数据2是:"+var2+"<br>") <BR>document.write("数据相加是:"+varadd+"<br>") <BR>document.write("数据相减是:"+varsub+"<br>") <BR>document.write("数据相乘是:"+varmult+"<br>") <BR>document.write("数据相除是:"+vardiv+"<br>") <BR>document.write("数据相除取余数是:"+varmod+"<br>") <BR></script>
2.递增变量和递减变量
<script> <BR>days=1 <BR>document.write("输出变量"+days+"<br>") <BR>days++ <BR>document.write("递增后变量变为:"+days) <BR></script>
3.创建比较表达式
<script> <BR>daysofmonth=28 <BR>if(daysofmonth==28) <BR>month="february" <BR>document.write("days of month:"+daysofmonth+"<br>") <BR>document.write("month:"+month) <BR></script>
4.创建逻辑表达式
<script> <BR>dayofmonth=28 <BR>if(dayofmonth==28 || dayofmonth==29) <BR>month="february" <BR>document.write("days of month:"+dayofmonth+"<br>") <BR>document.write("month:"+month) <BR></script>
5.使用条件运算符
<script> <BR>stomach="hungry"; <BR>time="5:00"; <BR>(stomach=="hungry"&&time=="5:00") ? eat = "dinner":eat="a snack"; <BR>document.write("输出结果"+eat); <BR></script>
6.识别数字
<script> <BR>var1=24; <BR>(isNaN(var1))?document.write("变量var1"+var1+"不是数字"):Document.write("变量var1"+var1+"是数字") <BR></script>
第四章 控制程序流程
1.使用IF –Else语句
<script> <BR>month="december" <BR>date=25 <BR>if(month=="december" && date==25) <BR>document.write("今天是圣诞节,商店关门") <BR>else <BR>document.write("欢迎,您来商店购物") <BR></script>
2.使用for 循环
<script> <BR>for (count=1;count<=10;count++) <BR>document.write("输出第"+count+"句"+"<br>") <BR></script>
3.使用while循环
<script> <BR>count=1 <BR>while(count<=15){ <BR>document.write("输出第"+count+"句" +"<br>") <BR>count++} <BR></script>
4.中断循环
<script> <BR>count=1 <BR>while(count<=15){ <BR>count++ <BR>if(count==8) <BR>break; <BR>document.write("输出第"+count+"句"+"<br>")} <BR></script>
5.继续循环
<script> <BR>count=1 <BR>while(count<=15){ <BR>count++ <BR>if(count==8) <BR>continue; <BR>document.write("输出第"+count+"句"+"<br>")} <BR></script>
6.使用javascript定时器
<script> <BR>function rabbit() <BR>{document.write("输出语句") <BR>} <BR></script>


7.设置定期间隔
<script> <BR>window.setInterval("document.form1.text2.value=document.form1.text1.value",3000) <BR></script>






8.清除超时和间隔
<script> <BR>stop=window.setInterval("document.form1.text2.value=document.form1.text1.value",300) <BR></script>







第五章 使用函数
1.声明函数
<script> <BR>function quote() <BR>{ document.write("输出语句") <BR>} <BR></script>
2.调用函数
<script> <BR>function quote() <BR>{ document.write("输出语句") <BR>} <BR>quote() <BR></script>
3.了解全局变量和局部变量
任何不用 var关键字声明的变量都是全局变量,任何在函数外声明的变量都是全局变量
4.将参数传送给函数
<script> <BR>function f(item) <BR>{document.write("输出参数"+item+"<br>") <BR>} <BR>f("fgdfgd") <BR>f("参数二") <BR></script>
5.从函数返回值
<script> <BR>function average(var1,var2,var3) <BR>{ave=(var1+var2+var3)/3; <BR>document.write("输出结果"); <BR>return ave; <BR>} <BR>document.write(average(34,56,78)) <BR></script>
6.通过HTML链接调用函数
<script> <BR>function quote(){ <BR>document.write(" 输出字符串") <BR>} <BR></script>
通过HTML链接调用函数
 通过HTML链接调用函数,直接写javascript语句
第六章 处理事件
1.检查鼠标单击



2.检测双击



3.创建悬停按钮
清华大学出版的事半功倍系列 javascript全部源代码_javascript技巧
4.检测按键



5.设置焦点

onfous=document.form1.text1.value='该文本框获得焦点'
onblur=document.form1.text1.value='该文本框失去焦点'>

6.检测下拉菜单选择




7.创建网页加载和卸载信息




第七章 使用对象
1.理解对象\属性和方法

<script> <BR>document.write("页面背景颜色是:"+document.bgColor) <BR>document.write("页面前景颜色是:"+document.fgColor) <BR></script>
2.使用网页元素对象
<script> <BR></script>





3.使用子对象



<script> <BR>document.form1.text1.value="gdfgfd" <BR></script>





<script> <BR>document.form1.radio1.checked=true <BR></script>
4.使用预定义对象
<script> <BR>str1="dgdfgdfgdfhf固定法固定法功夫攻打法" <BR>document.write(str1+"<br>") <BR>str2=str1.substr(5) <BR>document.write(str2+"<br>") <BR>document.write("输出圆的面积:"+Math.PI*Math.pow(5.0,2)) <BR></script>
5.创建新对象
<script> <BR>today=new Date() <BR>document.write("今天是"+(today.getMonth()+1)+"月"+today.getDate()+"日"+"<br>") <BR>document.write("现在是:"+today.toLocaleString()) <BR></script>
.6.引用当前对象



7.查看对象属性
<script> <BR>for(prop in window) <BR>{document.write("window."+prop+"="+window[prop]+"<br>");} <BR>for(prop2 in location) <BR>{document.write("location."+prop2+"="+location[prop]+"<br>");} <BR></script>
8.使用Array对象
<script> <BR>array=new Array(10) <BR>array[0]="bark" <BR>array[1]="apple" <BR>array[2]="nebula" <BR>array[3]="cookie" <BR>array[4]="technology" <BR>document.write("数组元素个数是"+array.Length+"<br>") <BR>document.write("用 join将数组合并"+array.join(" ")+"<br>") <BR>document.write(" 数组排序"+array.sort()) <BR></script>
9.使用 image 对象
清华大学出版的事半功倍系列 javascript全部源代码_javascript技巧
<script> <BR>document.write("图片提示是:"+document.images[0].alt+"<br>") <BR>document.write("图片边框大小是:"+document.images[0].broder) <BR></script>
10.预加载图像
<script> <BR>freddy=new Image() <BR>freddy.src=freddy.gif <BR></script>

,清华大学出版的事半功倍系列 javascript全部源代码_javascript技巧

11.改变图像
清华大学出版的事半功倍系列 javascript全部源代码_javascript技巧




12.使用link和anchor对象
锚点1

Microsoft

sohu

sina

<script> <BR>document.write("本页面共有"+document.links.length+"链接"+"<br>") <BR>document.write("本页面共有"+document.anchors.length+"锚点"+"<br>") <BR>document.write("第一个链接协议是"+document.links[0].protocol+"<br>") <BR>document.write("第一个链接路径是"+document.links[0].pathnamel+"<br>") <BR>document.write("第一个链接href是"+document.links[0].hrefl+"<br>") <BR></script>
13.改变链接
link



14.使用history对象



第八章 使用窗口
1.在浏览器的状态栏上显示文本

sohu

2.改变背景色
<script> <BR>document.bgColor="orange" <BR></script>
3.列举背景颜色

<script> <BR>document.write("当前背景色是:"+document.bgColor) <BR></script>

4.改变文本和链接颜色
<script> <BR>document.bgColor="orange" <BR>document.fgColor="blue" <BR>document.linkColor="red" <BR></script>

看看这段文本颜色


sohu

5.改变文档标题
<script> <BR>name="Mouse" <BR>document.title="welcome to "+name+"'s House" <BR>document.write(document.title) <BR></script>
6.显示修改日期
<script> <BR>document.write("本页面最后修改时间是"+document.lastModified) <BR></script>
7.查看当前文档的URL
<script> <BR>document.write("本页面的URL:"+document.URL) <BR></script>
8.查看引用页
<script> <BR>document.write("本页面的引用页是"+document.referrer) <BR></script>
9.打开新的浏览器窗口
<script> <BR>window.open("*.htm","title","width=200,height=400,resizable=yes") <BR></script>
10.关闭远程窗口
close.html:
<script> <BR>document.write("正文") <BR></script>




open.html
<script> <BR>window.open("close.html","romote","width=200,height=400,resizable=yes") <BR></script>
11.打印窗口
<script> <BR>document.write("正文") <BR></script>



12.移动窗口

水平方向
垂直方向




水平方向
垂直方向


13.改变窗口大小

水平方向
垂直方向




水平方向
垂直方向


14.用警告对话框通知用户
<script> <br><br>window.alert("welcome") <BR></script>
15.用提示对话框接受输入
<script> <BR>name=window.prompt("输入姓名","姓名") <BR>document.write(" 欢迎您:"+name+"来到这里") <BR></script>
16.用确认对话框使用户做出决定
<script> <BR>like=window.confirm("你觉得好吗?") <BR>if(like==true) <BR>document.write("谢谢你的夸奖") <BR>else <BR>document.write("希望得到你的夸奖") <BR></script>
第九章 使用字符串
1.使用字符串对象
<script> <BR>mystring="gdgdfgfddddaaaaaaaaaaaabbbbbbbbbbbbbbbbbvbhg.<br>" <BR>document.write(mystring) <BR>document.write(mystring.bold()) <BR>document.write(mystring.toUpperCase()) <BR></script>
2.使用子字符串
<script> <BR>str1="fdsf 1111 gfdgfd dfdsf cccc dddd.<br>" <BR>document.write(str1) <BR>document.write(str1.substring(0,13)+"<br>") <BR>document.write(str1.substr (20,11)+"<br>") <BR></script>
3.连接字符串
<script> <BR>str1="may you find" <BR>str2="peace,happiness and prosperity.<br>" <BR>document.write(str1+"<br>") <BR>document.write(str2) <BR>document.write(str1.concat(str2)) <BR>document.write(str1+=str2) <BR></script>
4.格式化字符串变量
<script> <BR>str1="peace,happiness and prosperity.<br>" <BR>document.write(str1) <BR>document.write(str1.big()) <BR>document.write(str1.small()) <BR>document.write(str1.bold()) <BR>document.write(str1.italics()) <BR>document.write(str1.strike()) <BR>document.write(str1.fontsize(6)) <BR>document.write(str1.fontcolor(green)) <BR></script>
5.创建锚和链接
<script> <BR>str1="this is the bigginning of the page.<br>" <BR>str2="….<br>" <BR>str3="this is the end of the page .<br>" <BR>str4="link to the start<br>" <BR>str5="link to the end<br>" <BR>document.write(str1.anchor("start")) <BR>for(i=0;i<10;i++) <BR>document.write(str2); <BR>document.write(str3.anchor("end")) <BR>document.write(str4.link("#start")) <BR>document.write(str5.link("#end")) <BR></script>
6.确定字符串长度
<script> <BR>str1="this is the bigginning of the page." <BR>document.write(str1+"<br>") <BR>document.write( "字符串的长度是:"+str1.length) <BR>document.write("字符串全部大写是;"+str1.toUpperCase()) <BR>document.write("字符串全部小写是;"+str1.toLowerCase()) <BR></script>
7.在字符串内搜索
<script> <BR>str1="this is the end of the line.<br>" <BR>document.write(str1) <BR>document.write("字符end在字符串的位置是"+str1.search("end")) <BR>document.write("字符dog在字符串的位置是"+str1.search("dog")) <BR></script>
8.定位字符串中的字符
<script> <BR>str1="spring is a time for flowers and trees and baby bunnles<br>" <BR>document.write(str1) <BR>document.write("the index for the second word ‘and' is"+str1.indexOf("and",30)) <BR>documednt.write("the last index of the word ‘and' is "+str1.lastIndexOf("and")) <BR></script>
9.替换字符串中的文本
<script> <BR>str1="spring is a time for flowers and trees and baby bunnles<br>" <BR>document.write(str1) <BR>document .write(str1.replace("and",",")) <BR></script>
10.字符串分离
<script> <BR>str1="spring is a time for flowers and trees and baby bunnles<br>" <BR>document.write(str1) <BR>str1array=str1.split(" ") <BR>document.write(str1array[0]+"<br>") <BR>document.write(str1array[1]+"<br>") <BR>document.write(str1array[2]+"<br>") <BR>document.write(str1array[3]+"<br>") <BR></script>
第十章 使用日期和时间
1.使用Date对象
<script> <BR>cdate=new Date("august 2,1989 12:30:00") <BR>document.write(cdate) <BR></script>
2.显示当地时间和日期
<script> <BR>cdate=new Date() <BR>document.write("当前时间是:"+cdate.toGMTString()+"<br>") <BR>document.write("日期和时间是:"+cdate.toLocaleString()) <BR></script>
3.获得时间和日期值
<script> <BR>cdate=new Date() <BR>document.write("显示当前的星期"+cdate.getDay()+"<br>") <BR>document.write("显示当前的月份"+cdate.getMonth()+"<br>") <BR>document.write("显示当前的日期"+cdate.getDay()+"<br>") <BR>document.write("显示当前的年份"+cdate.getYear()+"<br>") <BR>document.write("显示当前的小时"+cdate.getHours()+"<br>") <BR>document.write("显示当前的分钟"+cdate.getMinutes()+"<br>") <BR>document.write("显示当前的秒"+cdate.getSeconds()+"<br>") <BR></script>
4.设置时间和日期值
<script> <BR>cdate=new Date("December 25,1984") <BR>document.write("显示日期"+cdate+"<br>") <BR>document.write("设置月份"+cdate.setMonth(10)+"<br>") <BR>document.write("设置日期"+cdate.setDate(23)+"<br>") <BR>document.write("设置年份"+cdate.setYear(2000)+"<br>") <BR>document.write("设置小时"+cdate.setHours(13)+"<br>"); <BR>document.write("设置分钟"+cdate.setMinutes(47)+"<br>"); <BR>document.write("设置秒"+cdate.setSeconds(23)+"<br>"); <BR>document.write("显示设置后的日期和时间"+cdate); <BR></script>
第十一章 使用Math对象
1. 使用Math对象
<script> <BR></script>

圆的半径:

圆的面积:



2.生成随机数
<script> <BR>array1=new Array( <BR>"这是第1句", <BR>"这是第2句", <BR>"这是第3句", <BR>"这是第4句", <BR>"这是第5句", <BR>"这是第6句") <BR>RandomNo=Math.floor(array1.length*Math.random()) <BR>document.write("随机输出某一句"+"<br>"+array1[RandomNo]) <BR></script>
3.使用平方根

value:

平方根

onclick="document.form1.sqrt.value=Math.sqrt(document.form1.va1.value)">

4.数字的舍入

输入

舍入的结果



5.乘方运算

底数

指数





6.发现最小值和最大值

数字1

数字2

最小值

最大值

数字1

第十二章 使用表单
1.使用文本框



<script> <BR>document.write("表单text1类型是: "+document.form1.text1.type+"<br>") <BR>document.write("表单text1名称是: "+document.form1.text1.name+"<br>") <BR>document.write("表单text1值是: "+document.form1.text1.value+"<br>") <BR>document.write("表单text1大小是: "+document.form1.text1.size+"<br>") <BR></script>


onfocus=document.form1.text1.select()>

2.使用密码框



<script> <BR>document.write("表单pw1的类型:"+document.form1.pw1.type+"<br>") <BR>document.write("表单pw1的名称:"+document.form1.pw1.name+"<br>") <BR>document.write("表单pw1的值:"+document.form1.pw1.value+"<br>") <BR>document.write("表单pw1的大小:"+document.form1.pw1.size+"<br>") <BR></script>
3.使用隐藏字段



<script> <BR>document.write("表单hid1的类型:"+document.form1.hid1.type+"<br>") <BR>document.write("表单hid1的名称:"+document.form1.hid1.name+"<br>") <BR>document.write("表单hid1的值:"+document.form1.hid1.value+"<br>") <BR></script>
4.使用文本区域框



<script> <BR>document.write("表单ta1的类型:"+document.form1.ta1.type+"<br>") <BR>document.write("表单ta1的名称:"+document.form1.ta1.name+"<br>") <BR>document.write("表单ta1的值:"+document.form1.ta1.value+"<br>") <BR>document.write("表单ta1的横向宽度:"+document.form1.ta1.cols+"<br>") <BR>document.write("表单ta1的纵向宽度:"+document.form1.rows.value+"<br>") <BR></script>




5.使用按钮



<script> <BR>document.write("表单button1的类型:"+document.form1.button1.type+"<br>") <BR>document.write("表单button1的名称:"+document.form1.button1.name+"<br>") <BR>document.write("表单button1的值:"+document.form1.button1.value+"<br>") <BR></script>






6.使用重置按钮



<script> <BR>document.write("表单reset1的类型:"+document.form1.reset1.type+"<br>") <BR>document.write("表单reset1的名称:"+document.form1.reset1.name+"<br>") <BR>document.write("表单reset1的值:"+document.form1.reset1.value+"<br>") <BR></script>
7.使用提交按钮



<script> <BR>document.write("表单submit1的类型:"+document.form1.submit1.type+"<br>") <BR>document.write("表单submit1的名称:"+document.form1.submit1.name+"<br>") <BR>document.write("表单submit1的值:"+document.form1.submit1.value+"<br>") <BR></script>
8.使用复选按钮

computer savvy?

<script> <BR>document.write("表单cb1的类型:"+document.form1.cb1.type+"<br>") <BR>document.write("表单cb1是否被选择?:"+document.form1.cb1.checked+"<br>") <BR>document.write("表单cb1的名称:"+document.form1.cb1.name+"<br>") <BR></script>
9.使用单选按钮

male
female

<script> <BR>document.write("第一个按钮被选择"+document.form1.radio1[0].checked+"<br>") <BR>document.write("第二个按钮被选择"+document.form1.radio1[1].checked+"<br>") <BR>document.write("按钮的名称"+ document.form1.radio1[0].name+"<br>") <BR>document.write("按钮的个数"+document.form1.radio1.length) <BR></script>
10.使用选择列表



<script> <BR>document.write("这个选择列表的名称"+document.form1.select1.name+"<br>") <BR>document.write("这个选择列表的长度"+document.form1.select1.length+"<br>") <BR>document.write("这个选择列表当前被选择的索引号"+document.form1.select1.selectedIndex+"<br>") <BR>document.write("这个选择列表的尺寸"+document.form1.select1.size+"<br>") <BR></script>
11.验证表单的有效性
<script> <BR>function validate(){ <BR>if(document.form1.text1.value!='1'||'2'||'3'||'4'){ <BR>alert("请输入1~4的整数") <BR>} <BR>} <BR></script>

请输入1~4的整数:


12.控制表单焦点














第十三章 使用分栏
第十四章 使用navigator
1.使用navigator对象
<script> <BR>document.write("navigator对象的属性"+"<br>") <BR>document.write("appcodename:"+navigator.appCodeName+"<br>") <BR>document.write("appname::"+navigator.appName+"<br>") <BR>document.write("appversion:"+navigator.appVersion+"<br>") <BR>document.write("platform:"+navigator.platform+"<br>") <BR>document.write("userAgent:"+navigator.userAgent+"<br>") <BR></script>
<script> <BR>document.write("navigator对象的方法"+"<br>") <BR>document.write("javaEnabled():"+navigator.javaEnabled()) <BR></script>
2.检查用户的浏览器
<script> <BR>if(navigator.appName.indexOf("Microsoft")!=-1){ <BR>document.write("用户浏览器是微软的IE浏览器"+"<br>")} <BR>else if(navigator.appName.indexOf("Netscape")!=-1){ <BR>document.write("用户浏览器是netscape的netscape浏览器"+"<br>")} <BR>if(navigator.appVersion.indexOf("4.0")!=-1){ <BR>document.write("you are using a version 4.0compatible browser") <BR>} <BR>else{ <BR>document.write("this browser is not 4.0 compliant")} <BR></script>
3.检测用户的操作系统
<script> <BR>if (navigator.platform.indexOf("win32")!=-1){ <BR>document.write("you are using a computer running windows 95 or highter")} <BR>else{ <BR>document.write("this computer is not running windows 95 or higher")} <BR></script>
4.使用location对象
<script> <BR>document.write("location对象的属性"+"<br>") <BR>document.write("hash"+location.hash+"<br>") <BR>document.write("hostname"+location.hostname+"<br>") <BR>document.write("host"+location.host+"<br>") <BR>document.write("href"+location.href+"<br>") <BR>document.write("port"+location.port+"<br>") <BR>document.write("search"+location.search+"<br>") <BR></script>

重新加载网页



5.使用cookie
<script> <BR>finction makecookie(){ <BR>if(!document.cookie){ <BR>name=prompt("请输入你的姓名"); <BR>document.cookie="name="+name+";";} <BR>} <BR></script>


<script> <BR>function makecookie(){ <BR>if(!document.cookie){ <BR>name=prompt("请输入你的姓名") <BR>document.cookie="name="+name+";"; <BR>namestart=document.cookie.indexOf("="); <BR>nameend=document.cookieindexOf(";"); <BR>document.writeln("your name is:"+document.cookie.substring(namestart+1,nameend)+",br>") <BR>} <BR>} <BR></script>
來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板