1、alert,编写JavaScript脚本alert(“在页面上显示对话框“);在页面上显示对话框,confirm,编写JavaScript脚本document.write(confirm(“确认对话框“);确认对话框,prompt,编写JavaScript脚本var name; name=prompt(“你叫什么名字“); document.write(“欢迎“+name+“同志访问我们的网页“);,if,编写JavaScript脚本var x=prompt(“请输入一个整数“); if(x100)y=1+Math.sqrt(x); elsey=1-Math.sqrt(x); alert(y)
2、;,another if,编写JavaScript脚本var x=prompt(“请输入一个整数“); if(x100)y=1+Math.sqrt(x); else if(x=0)y=0; elsey=1-Math.sqrt(x); alert(y);,switch,编写JavaScript脚本var grade; grade=prompt(“请输入成绩等级(A,B,C,D,E)“); switch(grade) case A:y=“A:90100“;break; case B:y=“B:8089“;break; case C:y=“C:7079“;break; case D:y=“D:606
3、9“;break; case E:y=“E:,for,编写JavaScript脚本for(x=1;x“); for(x=12;x=0;x-=3)document.write(x+“,“);,for-in,编写JavaScript脚本var chararray=new Array(); for(x=0;x“);,while,编写JavaScript脚本var arr=new Array(); x=0; while(x,do-while,编写JavaScript脚本var arr=new Array(); x=0; doarrx=x; x+; while(x,continue & break,编写
4、JavaScript脚本var arr=new Array(); for(x=1;x“); var arr2=new Array(); for(x=1;x,math1,编写JavaScript脚本radius=prompt(“输入半径“); document.write(“半径为:“+radius); document.write(“); document.write(“周长为:“+2*radius*Math.PI); document.write(“); document.write(“面积为:“+Math.PI*radius*radius); document.write(“);,math
5、2,编写JavaScript脚本for(x=1;x“);,math3,编写JavaScript脚本document.write(“sin(30)=“+Math.sin(30)+“); document.write(“cos(30)=“+Math.cos(30)+“); document.write(“tan(30)=“+Math.tan(30)+“); document.write(“arcsin(0.5)=“+Math.asin(0.5)+“); document.write(“arccos(1)=“+Math.acos(1)+“); document.write(“arctan(1)=“+
6、Math.atan(1)+“);,编写JavaScript脚本today=new Date(); year=today.getFullYear(); month=today.getMonth()+1; day=today.getDate(); theweek=today.getDay(); var week; switch(theweek) case 0:week=“星期日“;break; case 1:week=“星期一“;break; case 2:week=“星期二“;break; case 3:week=“星期三“;break; case 4:week=“星期四“;break; cas
7、e 5:week=“星期五“;break; case 6:week=“星期六“;break; document.write(“今天是“+year+“年“+month+“月“+day+“日“+week+“) document.write(“欢迎来访!“);,date1,date2,编写JavaScript脚本today=new Date(); thehour=today.getHours(); theminute=today.getMinutes(); thesecond=today.getSeconds(); document.write(“现在是北京时间“+thehour+“:“+themi
8、nute+“:“+thesecond+“),date3,编写JavaScript脚本function showTime() 电子时钟:,function whowTime()var today=new Date();var thehour=today.getHours();var theminute=today.getMinutes();var thesecond=today.getSeconds();var timeVal=“ “;timeVal+=(thehour10)? “0“:“)+thehour;timeVal+=(theminute10)? “:0“:“:“)+theminute;
9、timeVal+=(thesecond10)? “:0“:“:“)+thesecond;timeVal+=(thehour12)? “AM“:“PM“);document.clock.time.value=timeVal;timerID=setTimeout(“showTime()“,1000); ,document,编写JavaScript脚本document.write(“当前文档的标题“+document.title+“); document.write(“当前文档的URL“+document.url+“); document.write(“当前文档的背景颜色“+document.bgcolor+“); document.write(“当前文档的最后修改日期“+document.lastModified+“);,