(1)window對象 彈塊的方法 提示塊: window.alert("提示信息"); Code: var res = alert("xxx"); alert(res); Code: var res = alert("xxx"); alert(res); 確認塊: window.confirm(" ...
(1)window對象
彈塊的方法
提示塊:
window.alert("提示信息");
Code: |
var res = alert("xxx"); alert(res); |
確認塊:
window.confirm("確認信息");
有返回值:如果點擊確認返回true,如果點擊取消返回false
code: |
var res = confirm("您確認要刪除嗎?"); alert(res); |
輸入框:prompt("提示信息");
有返回值:如果點擊確認返回輸入框的文本 點擊取消返回null
Code: |
var res = prompt("請輸入密碼?"); alert(res); |
open方法:
window.open("url地址");
Code: |
open("../jsCore/demo10.html"); |
定時器:
setTimeout(函數,毫秒值);
Code: |
setTimeout( function(){ alert("xx"); }, 3000 ); |
clearTimeout(定時器的名稱); //清除定時器
Code: |
<script type="text/javascript"> var timer; var fn = function(){ alert("x"); timer = setTimeout(fn,2000); }; var closer = function(){ clearTimeout(timer); }; fn(); </script> </head> <body> <input type="button" value="button" onclick="closer()"> </body> |
setInterval(函數,毫秒值);
Code: |
<script type="text/javascript"> var timer = setInterval( function(){ alert("nihao"); }, 2000 ); var closer = function(){ clearInterval(timer); }; </script> </head> <body> <input type="button" value="button" onclick="closer()"> </body> |
Code:註冊後5秒鐘跳轉首頁 |
<script type="text/javascript"> var time = 5; var timer; timer = setInterval( function(){ var second = document.getElementById("second"); if(time>=1){ second.innerHTML = time; time--; }else{ clearInterval(timer); location.href="../jsCore/demo10.html"; } }, 1000 ); </script>
</head> <body> 恭喜您註冊成功,<span id="second" style="color: red;">5</span>秒後跳轉到首頁,如果不跳轉請<a href="../jsCore/demo10.html">點擊這裡</a> </body> |
(2)location
location.href="url地址";
(3)history:歷史對象
back(); 回退
forward();前進
go();
code: |
<input type="button" value="上一頁" onclick="history.back()"> <input type="button" value="下一頁" onclick="history.forward()">
<input type="button" value="上一頁" onclick="history.go(-1)"> <input type="button" value="下一頁" onclick="history.go(1)">
|