关于Windows

一、History例子:具有“上一页”、“下一页”按钮的页面。

<html>
<body>
<form>
<input type="button" value="上一页" onClick="history.back()">
<input type="button" value="下一页" onClick="history.forward()">
</body>
</html>
二、Window对象的属性和方法

Window对象共有七个属性:
1 defauleStatus:指定窗口状态栏中的信息。
2 status:指定当前窗口状态栏中的信息。
3 frames:是一个数组,其中内容是窗口中所有的框架。
4 parent:指当前窗口的父窗口。
5 self:指当前窗口。
6 top:代表当前所有窗口的最顶层窗口。
7 window:代表当前窗口。
Window对象有五个方法:
1 alert:显示带有一个“确定”按钮的对话框。
2 confirm:显示带有“确定”与“取消”两个按钮的对话框。
3 prompt:显示带有输入区的对话框。
4 open:打开一个新窗口。
5 close:关闭用户打开的窗口。
三、status属性例子,在窗口状态栏显示和清除文字

单击"写入文字"按钮,在状态栏显示'这是状态栏'。按"清除文字"按钮,清除状态栏的文字。
<html>
<head>
<script>
function statbar(text) {
window.status = text; }
</script>
</head>
<body>
<form>
<input type="button" name="look" value="写入文字" onclick="statbar('这是状态栏');">
<input type="button" name="erase" value="清除文字" onclick="statbar('');">
</form>
</body>
</html>

四、alert方法例子:显示“大家来学习JavaScript脚本语言。”的对话框。

<html>
<body>
<script>
alert("大家来学习JavaScript脚本语言。")
</script>
</body>
</html>

五、 Confirm方法例子:让用户选择是否进入下一页。

用confirm显示选择对话框,按“确定”进入next.htm,按“取消”不进入。
<html>
<body>
<script>
if(confirm("你想进入下一页吗?"))
location="next.htm"
</script>
</body>
</html>

六、Prompt方法例子:让用户输入姓名,并将它显示出来。

用prompt显示输入对话框,让用户输入姓名,再用alert对话框显示出来。
<html>
<body>
<script>
var name
name=prompt("请输入姓名","小强")
alert("你好,"+name)
</script>
</body>
</html>

七、Window对象方法例子

当打开网页时,立即打开另一窗口,显示test.htm。
<html>
<body onload="javascript:window.open('test.htm')">
</body>
</html>
八、History对象的属性和方法

History对象只有一个length属性,它表示历史对象中的链接的数目。
History对象有以下方法:
back:在浏览器中显示上一页。
 forward:在浏览器中显示上下页。
 go(int):在浏览器中载入从当前算起的第int个页面。

posted on 2015-05-24 21:50  曾杰  阅读(120)  评论(0编辑  收藏  举报

导航