window,是javascript中整个框架中的根。它具有如下属性和方法:
属性:location,navigate,screen,frameset[],document,history等6个重要的属性.
方法:setTineOut(),moveTo(),moveBy(),resizeBy(),resizeTo()等几个常用的方法。
请看如下两个例子:
1、状态栏动态显示年月日
function setTime() {
var dt = new Date();
var strSt = dt.getFullYear() + "年" + (dt.getMonth()+1) + "月" + dt.getDate() + "日" + dt.getHours() + "时" + dt.getMinutes() + "分"+dt.getSeconds()+"秒";
//window.defaultStatus = strSt;
window.status = strSt;
setTimeout("setTime()", 1000);
}
2、移动窗口
var x=0;
var y=0;
function moveWin() {
((x + 0) < (window.screen.width + 0)) ? (x = x + 1) : x = 0;
((y + 0) < (window.screen.height + 0)) ? (y = y + 1) : y = 0;
window.moveTo(x, y);
setTimeout("moveWin()", 1);
}
JS窗口操作
本文介绍了JavaScript中window对象的使用,包括其重要属性如location、document、history等,以及常用方法如setTimeout()、moveTo()等,并通过两个实例展示了如何利用这些方法实现状态栏动态显示时间和自动移动浏览器窗口。
4万+

被折叠的 条评论
为什么被折叠?



