-------------------------------------------------- -------------------
注:頁面上元素name屬性以及JavaScript引用的名稱必須一致包括大小寫
否則會(huì)提示你1個(gè)錯(cuò)誤信息 "引用的元素為空或者不是對象"
-------------------------------------------------- -------------------
對象屬性
window //窗戶自身
window.self //引用本窗戶window=window.self
window.name //為窗戶命名
window.defaultStatus //設(shè)定窗戶狀態(tài)欄信息
window.location //URL地址,配備布置這個(gè)屬性可以打開新的頁面
-------------------------------------------------- -------------------
對象方法
window.alert("text") //提示信息會(huì)話框
window.confirm("text") //確認(rèn)會(huì)話框
window.prompt("text") //要求鍵盤輸入會(huì)話框
window.setIntervel("action",time) //每一隔指定的時(shí)間(毫秒)就執(zhí)行一次操作
window.clearInterval() //清除時(shí)間配備布置作用就是終止輪回
window.setTimeout(action,time) //隔了指定的時(shí)間(毫秒)執(zhí)行一次操作
window.open() //打開新的窗戶
window.close() //關(guān)閉窗戶
-------------------------------------------------- -------------------
成員對象
window.event
window.document //見document對象詳解
window.history
window.screen
window.navigator
window.external
-------------------------------------------------- -------------------
window.history對象
window.history.length //瀏覽過的頁面數(shù)
history.back() //撤退退卻
history.forward() //進(jìn)步
history.go(i) //到汗青詳細(xì)登記單的第i位
//i>0進(jìn)步,i<0撤退退卻
-------------------------------------------------- -------------------
window.screen對象
window.screen.width //屏幕寬度
window.screen.height //屏幕高度
window.screen.colorDepth //屏幕色深
window.screen.availWidth //可用寬度
window.screen.availHeight //可用高度(除去任務(wù)欄的高度)
-------------------------------------------------- -------------------
window.external對象
window.external.AddFavorite("地址","標(biāo)題" ) //把網(wǎng)站新增到保藏夾
-------------------------------------------------- -------------------
window.navigator對象
window.navigator.appCodeName //瀏覽器代碼名
window.navigator.appName //瀏覽器步伐名
window.navigator.appMinorVersion //瀏覽器補(bǔ)釘版本
window.navigator.cpuClass //cpu類型 x86
window.navigator.platform //操作體系類型 win32
window.navigator.plugins
window.navigator.opsProfile
window.navigator.userProfile
window.navigator.systemLanguage //客戶體系語言 zh-cn簡體中文
window.navigator.userLanguage //用戶語言,同上
window.navigator.appVersion //瀏覽器版本(包括 體系版本)
window.navigator.userAgent
window.navigator.onLine //用戶否在線
window.navigator.cookieEnabled //瀏覽器是否撐持cookie
window.navigator.mimeTypes
-------------------------------------------------- -------------------
<html>
<!--window對象方法舉出例子腳本-->
<script language="javascript">
window.alert("您好!")
</script>
<script language="javascript">
var action
action=window.confirm("請選擇操作...")
if(action)
document.write("您選擇了接續(xù)操作")
else
document.write("您選擇了勾銷操作")
</script>
<script language="javascript">
var info
info=window.prompt("請輸入一些必要的信息")
document.write (info)
</script>
<script language="javascript">
var i;i=0;
function action(){
i++;
window.alert(i) //監(jiān)督輪回情況
if(i>=10)
window.clearInterval(stop) //終止輪回
}
stop=window.setInterval("action()",1000)//1000毫秒=1秒
</script>
<script language="javascript">
var i;i=0;
function action(){
i++;
window.alert(i) //監(jiān)督輪回情況
}
window.setTimeout("action()",1000)
//不異的代碼setTimeout只執(zhí)行一次
</script>
</html>
例子1: setInterval:每一經(jīng)過指定毫秒值后計(jì)算1個(gè)抒發(fā)式 iTimerID = window.setInterval(vCode,iMilliSeconds[,sLanguage]) setTimeout:經(jīng)過指定毫秒值后計(jì)算1個(gè)抒發(fā)式 TimerID = window.setTimeout(vCode,iMilliSeconds[,sLanguage]) 1個(gè)簡略例子:2秒鐘彈出1個(gè)窗戶之后2秒鐘后封閉:
<script language="javascript">
var b;
function test(){
b=window.open('''','''','''');
window.setTimeout(aa,2000);
}
function aa(){
b.close();
}
window.setInterval(test,2000);
</script>
例子2:
⑴index.html
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>window舉出例子</title>
</head>
<script language="javascript">
<!--
//打開標(biāo)準(zhǔn)樣式窗戶
function open1(){
//配備布置標(biāo)準(zhǔn)樣式窗戶的一些狀態(tài)值
var windowStatus = "dialogWidth:260px;dialogHeight:180px;center:1;sta tus:0;";
//在標(biāo)準(zhǔn)樣式窗戶中打開的頁面
var url = "test.html";
//將標(biāo)準(zhǔn)樣式窗戶返回的值臨時(shí)生存
var temp = showModalDialog(url,"",windowStatus);
//將剛才生存的值賦給文本輸入框returnValue
document.all.returnValue.value = temp;
}
//打開無菜單窗戶
function open2(){
//配備布置窗戶的一些狀態(tài)值
var windowStatus = "left=380,top=200,width=260,height=200,resizable=0 ,scrollbars=0,menubar=no,status=0";
//在窗戶中打開的頁面
var url = "test1.html";
window.open(url,"noMenuWindowName",windowStatus);
}
//打開全屏窗戶
function open3(){
//配備布置窗戶的一些狀態(tài)值
var windowStatus = "fullscreen = 1";
//在窗戶中打開的頁面
var url = "test2.html";
window.open(url,"noMenuWindowName",windowStatus);
}
-->
</script>
<body>
<input type="button" name="btn1" value="打開標(biāo)準(zhǔn)樣式窗戶" onClick="open1()">
<br>
從標(biāo)準(zhǔn)樣式窗戶返回的值:
<input type="text" id="returnValue" name="returnValue">
<br><br>
<input type="button" name="btn2" value="打開無菜單窗戶" onClick="open2()">
<br><br>
<input type="button" name="btn3" value="打開全屏窗戶" onClick="open3()">
<br><br>
</body>
</html>
⑵test.html
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>在標(biāo)準(zhǔn)樣式窗戶中打開的頁面</title>
</head>
<script language="javascript">
<!--
//將選中的值師長教師存到隱含對象上
function ok(tempValue){
document.all.selectedValue.value = tempValue;
}
//封閉頁面時(shí)將隱含對象中的值傳回
function willReturnValue(){
window.returnValue = document.all.selectedValue.value;
window.關(guān)了();
}
-->
</script>
<body onUnload="willReturnValue()" bgcolor="#D4D0C8">
<center>
請單選您的愛好:
<br>
<br>
<input type="radio" name="lover" value="體育" onClick="ok(this.value)">體育
<br>
<input type="radio" name="lover" value="休閑文娛" onClick="ok(this.value)">休閑文娛
<br>
<input type="radio" name="lover" value="看書讀報(bào)" onClick="ok(this.value)">看書讀報(bào)
<br>
(3)test1.html
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>在無菜單窗戶中打開的頁面</title>
</head>
<body bgcolor="#D4D0C8">
<center>
請單選您的愛好:
<br>
<br>
<input type="radio" name="lover" value="體育">體育
<br>
<input type="radio" name="lover" value="休閑文娛">休閑文娛
<br>
<input type="radio" name="lover" value="看書讀報(bào)">看書讀報(bào)
<br>
<input type="radio" name="lover" value="琴棋字畫">琴棋字畫
</center>
</body>
</html>
?、萾est2.html
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>在全屏窗戶中打開的頁面</title>
</head>
<body bgcolor="#D4D0C8">
<center>
請單選您的愛好:
<br>
<br>
<input type="radio" name="lover" value="體育">體育
<br>
<input type="radio" name="lover" value="休閑文娛">休閑文娛
<br>
<input type="radio" name="lover" value="看書讀報(bào)">看書讀報(bào)
<br>
<input type="radio" name="lover" value="琴棋字畫">琴棋字畫
<br>
<br>
<input type="button" name="btn1" value="封閉" onClick="window.關(guān)了()">
</center>
</body>
</html>
<input type="radio" name="lover" value="琴棋字畫" onClick="ok(this.value)">琴棋字畫
<input type="hidden" id="selectedValue" name="selectedValue">
</center>
</body>
</html>
本站僅提供存儲(chǔ)服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請
點(diǎn)擊舉報(bào)。