name= window. prompt("请输入你的姓名:"name) window. alert(name+"你好!下面要开始考试了!") if( window. confirm("你确实准备好了吗?") window location hrefexam }; </script> ·open方法:( chapter3/ /section4 windowopen,asp) HiE: winhwnd=window open(url, windowname, paralist) <metahttp-equiv="content-typecontent=texT/html;charset=gb2312"1> tfe无标题文档< / title ascript> function openwin(url)i newin=window open(url, winname", toolbar-no, directories=no, menubar=no, scrollbars=yes, rds zable=no, width=500, height=360") newin focus( < a href="#" on click=" JavaScript: openwin( meintro.asp)">作者简介<a> cloe方法:举例说明 <div align=center"><a href=# on Click="JavaScript: self. close(">*P</a></c settimeout方法:创建定时器,经过指定的毫秒后,自动调用指定的语句 clearTimeout方法:清除定时器;( chapterl3 section4/ clock. asp) <metahttp-equiv="content-type"content="text/html;charset=gb2312> <ttle>时钟</ title e="JavaScript"> var timer var now=new Date var minutes=now. get Minutes(; ar seconds=now. getSecondso
name=""; name=window.prompt("请输入你的姓名:",name); window.alert(name+"你好!下面要开始考试了!"); if (window.confirm("你确实准备好了吗?")){ window.location.href="exam.asp"; }; </script> ⚫ open 方法:(chapter03/section4/ windowopen.asp) 用法:winhwnd=window.open(url,windowname,paralist) <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <title>无标题文档</title> <script language="javascript"> function openwin(url) { var newwin=window.open(url,"winname","toolbar=no,directories=no,menubar=no,scrollbars=yes,rdsi zable=no,width=500,height=360"); newwin.focus(); return(newwin); } </script> </head> <body> <a href="#" onClick="JavaScript:openwin('meintro.asp')">作者简介</a> </body> ⚫ close 方法:举例说明 <div align="center"><a href=# onClick="JavaScript:self.close()">关闭</a></div> ⚫ setTimeout 方法:创建定时器,经过指定的毫秒后,自动调用指定的语句; ⚫ clearTimeout 方法:清除定时器;(chapter03/section4/ clock.asp) <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> <title>时钟</title> <script language="JavaScript"> var timer; function clock() { var timestr=""; var now=new Date(); var hours=now.getHours(); var minutes=now.getMinutes(); var seconds=now.getSeconds();
timestr+=hours. imestr+=((minutes<10)?:0": " )+minutes window. document. frmclock txttime value=timestr imer=set Timeout('clock 0, 1000) ∥设置定时器 function stopito iclear Timeout( timer); i </head <form action=""method="post"name="rmclock"id="rmclock"> 时间: <input name="txttime"type="text"id="txttime"> < cinput type=" button"name=" Submit'" value="启动始终" onclick=" clocko"> < -input type=" button"name=" Submit2" values="停止时钟" onclick=" stepit"> < /form> /htmI> ·将上述程序稍加更改,可以创建定时闹钟程序( chapter3 /section4/ clertclock. asp <ttle→时钟</ title> function clock( i ar tamest now. getHourso var seconds-now. getSecondso timestr+=hours. window. document frmclock txttime value=timestr If(window. document rmclock settime value==timestr) i
timestr+=hours; timestr+=((minutes<10)? ":0" : ":")+minutes; timestr+=((seconds<10)? ":0" : ":")+seconds; window.document.frmclock.txttime.value=timestr; timer=setTimeout('clock()',1000); //设置定时器 } function stopit() {clearTimeout(timer);} </script> </head> <body> <form action="" method="post" name="frmclock" id="frmclock"> <p> 当前时间: <input name="txttime" type="text" id="txttime"> </p> <p> <input type="button" name="Submit" value="启动始终" onclick="clock()"> <input type="button" name="Submit2" value="停止时钟" onclick="stopit()"> </p> </form> </body> </html> ⚫ 将上述程序稍加更改,可以创建定时闹钟程序(chapter03/section4/ clertclock.asp) <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> <title>时钟</title> <script language="JavaScript"> var timer; function clock() { var timestr=""; var now=new Date(); var hours=now.getHours(); var minutes=now.getMinutes(); var seconds=now.getSeconds(); timestr+=hours; timestr+=((minutes<10)? ":0" : ":")+minutes; timestr+=((seconds<10)? ":0" : ":")+seconds; window.document.frmclock.txttime.value=timestr; if (window.document.frmclock.settime.value==timestr) {
window. alert("起床啦!") timer=set Timeout(clockO, 1000) function stopito (clear Timeout(timer); <head> <bod <form action=" method="post"name="rmclock"id="rmclock"> 当前时间: nput name="txttime"type=text"id="txttime"> p>设定闹钟 <input name="settimetype="text"id="settime < <input type=" button"name=" Submit"vlue="启动始终" onclick=" clock( < -input type=" button"name=" Submit" values="停止时钟" onclick=" stopit(" /body> /html> 3、 location对象:该对象包含有当前网页的URL(统一资源定位器,即网址)。 属性:href用于指定导航到的网页( chapter3 section4/ frontpage. asp) 举例 < ca href=# on Click=" Javascript window location. href=nextpage. asp">按此处到下一个页面 4、 history对象:该对象包含有最近10个网页的URL的地址。常用的方法为go(数值)方 法,数值为负数往回,等价于浏览器中的“后退”。 举例: <body>(chapter03/section4/nextpage. asp) < a href=# on click= Javascript: window history.go(-1)>该网页是跳转后的页面请按此处回到 上一个页面!<a> body> 5、 external对象:该对象有一个常用的 add Favorite方法,利用该方法,可实现将指定的网
window.alert("起床啦!"); } timer=setTimeout('clock()',1000); } function stopit() {clearTimeout(timer);} </script> </head> <body> <form action="" method="post" name="frmclock" id="frmclock"> <p> 当前时间: <input name="txttime" type="text" id="txttime"> </p> <p>设定闹钟: <input name="settime" type="text" id="settime"> </p> <p> <input type="button" name="Submit" value="启动始终" onclick="clock()"> <input type="button" name="Submit2" value="停止时钟" onclick="stopit()"> </p> </form> </body> </html> 3、location 对象:该对象包含有当前网页的 URL(统一资源定位器,即网址)。 ⚫ 属性: href 用于指定导航到的网页(chapter03/section4/ frontpage.asp) 举例: <body> <a href=# onClick="Javascript:window.location.href='nextpage.asp'"> 按此处到下一个页面 </a> </body> 4、history 对象:该对象包含有最近 10 个网页的 URL 的地址。常用的方法为 go(数值)方 法,数值为负数往回,等价于浏览器中的“后退”。 举例: <body>(chapter03/section4/ nextpage.asp) <a href=# onClick="Javascript:window.history.go(-1)">该网页是跳转后的页面,请按此处回到 上一个页面!</a> </body> 5、external 对象:该对象有一个常用的 addFavorite 方法,利用该方法,可实现将指定的网
页添加到收藏夹中 body>(chapter03/section4/externalpage. asp) 这是一个值得珍藏的网页!< a href=# onClick="Javascript:window.externaladdFavorite(http://vwwahip.cn;安徽工业职业技术 学院)">点击珍藏<a> 6、 document对象:代表当前网页,其常用方法为wite用于在当前页面中输出HIML语句: <script language="javascript">(chapter03/section 4/document. asp) var curday=new Date document. write("今天是:") switch(curday. getDayo) 4 case document. write("星期一"); break; case 2 document. write("星期二") break document write("星期三"); break case 4 document. write("星期四") break case 5 document. write("星期五"), break, case document. write(" font color=FFO00星期六<font"), break document. write("< font color=FF000星期日</font>"). break 7、 JavaScript的事件处理 JavaScript采用了事件驱动的响应机制,用户在网页中的交互操作,将触发相应的事件, 事件发生时,系统会调用执行对应的事件处理函数 事件:由系统预先定义好的,能被对象识别的一种动作。 事件的类别:系统事件(Load, Unload)和用户事件 Mouse Over, Mouse Out, Mouse Downdown, Click, KeyDown, KeyUp f 事件的响应通过On与事件名称组成,比如 Click事件,对应的事件为 On Click 事件句柄=事件处理函数()或语句 举例:( chapter3/ section5/ eventwelcom. asp) < <input Type=' button”vaue=”确定” On Click=" Checkit(O” body Onload=”poup(O”> body OnLoad= alert(“欢迎光临本站”)> < body OnUnLoad= alert(“谢谢光临本站”)> 表单对象的常用事件; 举例,完成表单数据的检验( chapter3/ / 5/ register.;asp)
页添加到收藏夹中 <body>(chapter03/section4/ externalpage.asp) 这是一个值得珍藏的网页!<a href=# onClick="Javascript:window.external.addFavorite('http://www.ahip.cn','安徽工业职业技术 学院')">点击珍藏</a> </body> 6、document 对象:代表当前网页,其常用方法为 write 用于在当前页面中输出 HTML 语句; <script language="javascript">(chapter03/section4/document.asp) var curday=new Date(); document.write("今天是:"); switch(curday.getDay()) { case 1: document.write("星期一");break; case 2: document.write("星期二");break; case 3: document.write("星期三");break; case 4: document.write("星期四");break; case 5: document.write("星期五");break; case 6: document.write("<font color='FF0000'>星期六</font>");break; case 0: document.write("<font color='FF0000'>星期日</font>");break; } </script> 7、JavaScript 的事件处理 JavaScript 采用了事件驱动的响应机制,用户在网页中的交互操作,将触发相应的事件,当 事件发生时,系统会调用执行对应的事件处理函数。 事件:由系统预先定义好的,能被对象识别的一种动作。 事件的类别:系统事件(Load,Unload)和用户事件 (MouseOver,MouseOut,MouseDowndown,Click,KeyDown,KeyUp 等 事件的响应通过 On 与事件名称组成,比如 Click 事件,对应的事件为 OnClick 事件句柄=事件处理函数()或语句 举例:(chapter03/section5/ eventwelcom.asp) <input Type=”button” value=”确定” OnClick=”Checkit()”> <body OnLoad=”poup()”> <body OnLoad=:alert(“欢迎光临本站”):> <body OnUnLoad=:alert(“谢谢光临本站”):> 表单对象的常用事件; 举例,完成表单数据的检验(chapter03/section5/ register.asp)