JavaScript 简单示例--窗口操作

来源:互联网 发布:c语言黑客编程pdf 编辑:程序博客网 时间:2024/06/05 15:30

窗口操作

1.test.html程序清单:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html>  <head>    <title>窗口操作</title>    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">    <meta http-equiv="description" content="this is my page">    <meta http-equiv="content-type" content="text/html; charset=UTF-8">        <!--<link rel="stylesheet" type="text/css" href="./styles.css">--><script type="text/javascript">var timer1, timer2;var num = 0;function click1() {alert("这是一个用alert方法弹出警告窗口示例!");}function click2() {if (confirm("你学会如何使用confirm窗口了吗?"));elsealert("那就继续努力吧!");}function click3() {var a = 0;a = prompt("你喜欢哪个数字,1或者2?请在下面输入:", 1);document.myform.count.value=a;}function click4() {timer1 = setInterval("count1()", 1000);}function click5() {clearInterval(timer1);}function click6() {timer2 = setTimeout("count2()", 5000);}function count1() {num++;document.myform.count.value=num;}function count2() {open('fz.html', '', 'height=150, width=300');}</script>  </head>    <body>    <center>    <h1>窗口操作</h1>    <hr/>    <form name="myform">    <input type="button" value="alert 窗口" onClick="click1();">    <input type="button" value="confirm 窗口" onClick="click2()">    <input type="button" value="prompt 窗口" onClick="click3()">    <hr/>    显示文本框:    <input type="text" name="count" size="10"/>    <hr/>    计时器1:    <input type="button" value="开始计时" onClick="click4()">    <input type="button" value="计时结束" onClick="click5()">    计时器2:    <input type="button" value="开始计时" onClick="click6()">    </form>    </center>  </body></html>

2.fz.html程序清单:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html>  <head>    <title>辅助窗口</title>    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">    <meta http-equiv="description" content="this is my page">    <meta http-equiv="content-type" content="text/html; charset=UTF-8">        <!--<link rel="stylesheet" type="text/css" href="./styles.css">-->  </head>    <body onclick="self.close()">    <center>    <h2>计时结束</h2>    <hr/>    <h2>单击关闭页面</h2>    </center>  </body></html>

运行结果: