-
<!DOCTYPE HTML>
<html>
<head>
? ?<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
? ?<title>screen</title>
</head>
<script type="text/javascript">
? ?/*
? ?window.screen 對象屬性
.screen.availHeight ?窗口可以使用的屏幕高度,單位像素
.screen.availWidth ?窗口可以使用的屏幕寬度,單位像素
.screen.height ?屏幕的高度,單位像素
.screen.width ?屏幕的寬度,單位像素
.screen.colorDepth ?用戶瀏覽器表示的顏色位數,通常為32位
.screen.pixelDepth ?用戶瀏覽器表示的顏色位數,通常為32位(IE瀏覽器不支持此屬性)
? ?*/
? ?document.write(window.screen.availHeight + "<br>");
? ?document.write(window.screen.availWidth + "<br>");
? ?document.write(window.screen.height + "<br>");
? ?document.write(window.screen.width + "<br>");
? ?document.write(window.screen.colorDepth + "<br>");
? ?document.write(window.screen.pixelDepth + "<br>");
</script>
<body>
</body>
</html>查看全部 -
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>navigator</title>
<script type="text/javascript">
? function validB(){?
? ? var u_agent = window.navigator.userAgent;?
? ? var B_name="不是想用的主流瀏覽器!";?
? ? if(u_agent.indexOf("Firefox")>-1){?
? ? ? ? B_name="Firefox";?
? ? }else if(u_agent.indexOf("Chrome")>-1){?
? ? ? ? B_name="Chrome";?
? ? }else if(u_agent.indexOf("MSIE")>-1&&u_agent.indexOf("Trident")>-1){?
? ? ? ? B_name="IE(8-10)"; ?
? ? }
? ? ? ? document.write("瀏覽器:"+B_name+"<br>");
? ? ? ? document.write("u_agent:"+u_agent+"<br>");?
? }?
</script>
</head>
<body>
? <form>
? ? ?<input type="button" value="查看瀏覽器" onclick="validB()" ?>
? </form>
</body>
</html>
查看全部 -
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Navigator</title>
</head>
<script type="text/javascript">
/*
window.navigator. 對象屬性:
appName 瀏覽器的名稱
appVersion 瀏覽器的平臺和版本信息
appCodeName 瀏覽器代碼名的字符串表示
platform 運行瀏覽器的操作系統平臺
userAgent 客戶機發送服務器的user-agent頭部的值
*/
? document.write(window.navigator.appName + "<br>");
? document.write(window.navigator.appVersion + "<br>");
? document.write(window.navigator.appCodeName + "<br>");
? document.write(window.navigator.platform + "<br>");
? document.write(window.navigator.userAgent + "<br>");
</script>
<body>
</body>
</html>
查看全部 -
? ? ? ?location 對象屬性:
? ? ? ?window.location.href ?設置或返回 完整的URL
? ? ? ?window.location.hash 設置或返回 從井號(#)開始的URL(錨)
? ? ? ?window.location.host 設置或返回 主機名和當前URL的端口號
? ? ? ?window.location.hostname 設置或返回 當前URL的主機名
? ? ? ?window.location.port 設置或返回 當前URL的端口號
? ? ? ?window.location.pathname 設置或返回 當前URL的路徑部分
? ? ? ?window.location.protocol 設置或返回 當前URL的協議
? ? ? ?window.location.search 設置或返回 從問號(?)開始的URL(查詢部分)
? ? ? ?location 對象方法:
? ? ? ?reload() ?重新加載當前文檔
? ? ? ?assign() ?加載新的文檔,有可點擊返回上一個頁面
? ? ? ?replace() 用新的文檔替代當前文檔,沒有返回一頁查看全部 -
<!DOCTYPE HTML>
<html>
<head>
? ?<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
? ?<title>無標題文檔</title>
? ?<script type="text/javascript">
? ? ? ?/*
? ? ? ?location 對象屬性:
? ? ? ?window.location.href ?設置或返回 完整的URL
? ? ? ?window.location.hash 設置或返回 從井號(#)開始的URL(錨)
? ? ? ?window.location.host 設置或返回 主機名和當前URL的端口號
? ? ? ?window.location.hostname 設置或返回 當前URL的主機名
? ? ? ?window.location.port 設置或返回 當前URL的端口號
? ? ? ?window.location.pathname 設置或返回 當前URL的路徑部分
? ? ? ?window.location.protocol 設置或返回 當前URL的協議
? ? ? ?window.location.search 設置或返回 從問號(?)開始的URL(查詢部分)
? ? ? ?location 對象方法:
? ? ? ?reload() ?重新加載當前文檔
? ? ? ?assign() ?加載新的文檔,有可點擊返回上一個頁面
? ? ? ?replace() 用新的文檔替代當前文檔,沒有返回一頁
? ? ? ?*/
? ? ? ?document.write(" ? ? ? ? ? ? ? ?window.location. 屬性:<br>");
? ? ? ?document.write(" ? ? ? ? ? ? ? ? ? ? ?.href 完整的URL: " + window.location.href + "<br>");
? ? ? ?document.write(" ? ? ? .hash 從井號(#)開始的URL(錨): " + window.location.hash + "<br>");
? ? ? ?document.write(" ? ? ? ? ?.host 主機名和當前URL的端口號: " + window.location.host + "<br>");
? ? ? ?document.write(" ? ? ? ? ? ? .hostname 當前URL的主機名: " + window.location.hostname + "<br>");
? ? ? ?document.write(" ? ? ? ? ? ? ? ? .port 當前URL的端口號: " + window.location.port + "<br>");
? ? ? ?document.write(" ? ? ? ? ? .pathname 當前URL的路徑部分: " + window.location.pathname + "<br>");
? ? ? ?document.write(" ? ? ? ? ? ? ?.protocol 當前URL的協議: " + window.location.protocol + "<br>");
? ? ? ?document.write(".search 從問號(?)開始的URL(查詢部分): " + window.location.search + "<br>");
? ? ? ?function locReload() {
? ? ? ? ? ?window.location.reload()
? ? ? ?}
? ? ? ?function locAssign() {
? ? ? ? ? ?window.location.assign("https://baidu.com")
? ? ? ?}
? ? ? ?function locReplace() {
? ? ? ? ? ?window.location.replace("https://baidu.com")
? ? ? ?}
? ?</script>
</head>
<body>
<br/><br/>
reload() 重新加載當前文檔:
<form>
? ?<input type="button" value="重新加載當前文檔" onclick="locReload()"/>
</form>
<br/><br/>
assign() 加載新的文檔,有可點擊返回上一個頁面:
<form>
? ?<input type="button" value="加載新的文檔" onclick="locAssign();"/>
</form>
<br/><br/>
replace() 用新的文檔替代當前文檔,沒有返回一頁:
<form>
? ?<input type="button" value="用新的文檔替代當前文檔" onclick="locReplace()"/>
</form>
</body>
</html>查看全部 -
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>無標題文檔</title>
</head>
?<script type="text/javascript">
? ? ? ? function GoBack() {
? ? ? ? ? ? window.history.back();
? ? ? ? }
? ? ? ? function GoForward() {
? ? ? ? ? ? window.history.forward();
? ? ? ? }
? ? </script>
<body>
? ? 點擊下面的錨點鏈接,添加歷史列表項: ? ?
? ? <br />
? ? <a href="#target1">第一個錨點</a>
? ? <a name="target1"></a>
? ? <br />
? ? <a href="#target2">第二個錨點</a>
? ? <a name="target2"></a>
? ? <br /><br />
? ? 使用下面按鈕,實現返回前或下一個頁面:
? ? <form>
? ? ? ?<input type="button" ?value="返回前一個頁面" onclick="GoBack();" />
? ? ? ?<input type="button" ?value="返回下一個頁面" onclick="GoForward();" />?
? ? </form>
</body>
</html>
查看全部 -
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>History對象</title>
</head>
<script type="text/javascript">
? var HL = window.history.length;
? document.write(HL);
</script>
<body>
</body>
</html>
查看全部 -
<!DOCTYPE HTML>
<html>
<head>
? ?<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
? ?<title>計時器</title>
? ?<script type="text/javascript">
? ? ? ?var num=0;
? ? ? ?function startCount() {
? ? ? ? ? ?document.getElementById('count').value=num;
? ? ? ? ? ?num=num+1;
? ? ? ? ? ?setTimeout("startCount()", 1000);
? ? ? ?}
? ?</script>
</head>
<body>
<form>
? ?<input type="text" id="count" />
? ?<input type="button" value="Start" onclick="startCount()"/>
</form>
</body>
</html>查看全部 -
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>計時器</title>
<script type="text/javascript">
? ?function clock(){
? ? ? var time=new Date(); ? ? ? ? ? ? ? ?
? ? ? document.getElementById("clock").value = time;
? ?}
? ?var ic = setInterval(clock, 1000);
</script>
</head>
<body>
<form>
? ? <input type="text" id="clock" size="50" ?/>
? ? <input type="button" value="Stop" onclick="clearInterval(ic)" />
</form>
</body>
</html>
查看全部 -
<!DOCTYPE HTML>
<html>
<head>
? ?<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
? ?<title>定時器</title>
? ?<script type="text/javascript">
? ? ? ?var attime;
? ? ? ?function clock(){
? ? ? ? ? ?var time=new Date();
? ? ? ? ? ?attime= time.getHours() + ":" + time.getMinutes() + ":" + time.getSeconds();
? ? ? ? ? ?document.getElementById("clock").value = attime;
? ? ? ?}
? ? ? ?setInterval(clock, 1000);
? ?</script>
</head>
<body>
<form>
? ?<input type="text" id="clock" size="50" ?/>
</form>
</body>
</html>查看全部 -
window對象方法:
alert() 顯示一段小學和一個確認按鈕的警告框。
prompt() 顯示可提示用戶輸入的對話框。
confirm() 顯示帶有一段消息以及確認按鈕和取消按鈕的對話框。
open() 打開一個新的瀏覽器窗口或查找一個已命名的窗口。
close() 關閉瀏覽器窗口。
print() 打印當前窗口的內容。
focus() 把鍵盤交點給予一個窗口。
blur() 把鍵盤焦點從頂層窗口移開。
moveBy() 可相對窗口的當前坐標把它移動指定的像素。
moveTo() 把窗口的左上角移動到一個指定的坐標。
resizeBy() 按照指定的像素調整窗口的大小。
resizeTo() 把窗口的大小調整到指定的寬度和高度。
scrollTo() 把內容關東到指定的坐標。
setInterval() 每隔指定的時間執行代碼。
setTimeout() 在指定的延遲時間之后來執行代碼。
clearInterval() 取消setInterval() 的設置
clearTimeout() 取消setTimeout() 的設置
查看全部 -
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>window對象</title>
<script type="text/javascript">
? ?alert("歡迎來到慕課網");
? ?function openw() {
? ? ? ?window.open("http://www.xianlaiwan.cn","_blank", "width=600,height=400");
? ?}
</script>
</head>
<body>
<form>
<input type="button" value="點擊我,打開新窗口" ?onclick="openw()"/>
</form>
</body>
</html>
查看全部 -
<!DOCTYPE ?HTML>
<html >
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>系好安全帶,準備啟航</title>
<script type="text/javascript">
? //通過javascript的日期對象來得到當前的日期,并輸出。
? var d = new Date();
? //document.write(d.getDate()+"<br>");
? var weekday=["星期日","星期一","星期二","星期三","星期四","星期五","星期六"];
? //document.write(weekday[d.getDay()]+"<br>");
??
? //成績是一長竄的字符串不好處理,找規律后分割放到數組里更好操作哦
? var scoreStr = "小明:87;小花:81;小紅:97;小天:76;小張:74;小小:94;小西:90;小伍:76;小迪:64;小曼:76";
? var nf = scoreStr.split(";");
? //document.write(nf+"<br>" + nf.length + "<br>");
?
? //從數組中將成績撮出來,然后求和取整,并輸出。
? var sum = 0;
? for(var i = 0; i < nf.length; i++) {
? ? ? //document.write(nf[i] + "<br>");
? ? ? var f = nf[i].substring(nf[i].indexOf(":")+1);
? ? ? //document.write(f + "<br>");
? ? ? sum = sum + parseInt(f);
? ? ? //document.write("sum = " + sum + "<br>")
? }
? document.write(d.getFullYear() + "年" + (d.getMonth() + 1) + "月" + d.getDate() + "日 " + weekday[d.getDay()]+ ", 平均分:"+ ?Math.round(sum / nf.length));
</script>
</head>
<body>
</body>
</html>
查看全部 -
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Array對象 </title>
<script type="text/javascript">
? ?function sortNum(a,b) {
? ? ?// 降序
? ? ?return b - a;
? ? ?// 升序 return a - b;
? ?}
var myarr = new Array("80","16","50","6","100","1");
document.write(myarr.sort(sortNum));
</script>
</head>
<body>
</body>
</html>
查看全部 -
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Array對象 </title>
<script type="text/javascript">
? ?var myarr1= ["我","愛","你"];
? ?document.write(myarr1.slice(1));
</script>
</head>
<body>
</body>
</html>
查看全部
舉報