標籤:javascript
一:history對象
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>無標題文檔</title>
</head>
<script type="text/javascript">
//history對象 記錄使用者訪問的url
function myback(){
window.alert(history.length);
window.history.go(-1);
}
</script>
<body>
<h1>b.html</h1>
<input type="button" onClick="myback()" value="返回上次頁面1"/>
</body>
</html>
二:location對象
<script type="text/javascript">
//location對象包含當前url的資訊
function myfresh(){
window.location.reload();
}
//每隔十秒重新整理頁面
window.setInterval("myfresh()",10000);
</script>
三:navigator對象
<script type="text/javascript">
//navigator該對象包括瀏覽器的資訊,想看該對象下的所有屬性可以通過遍曆獲得。
for(var key in navigator){
document.write("<br>"+key+"="+navigator[key]);
}
</script>
四:event對象
案例一:
<script type="text/javascript">
var i=5;
function countTime(){
i--;
mybut.value="同意 "+i;
if(i==0){
mybut.disabled=false;
window.clearInterval(mytimer);
}
}
var mytimer=window.setInterval("countTime
()",1000);
</script>
<body>
<P>
註冊條款
</p>
<input type="button" id="mybut" disabled="true" value="同意 5">
</body>
案例二:檢測滑鼠移動
<script type="text/javascript">
function test(){
showxy.innerText="x="+window.event.screenX+"y="+window.event.screenY;
}
</script>
</head>
<body>
<div onmousemove="test();" style="width:400px;height:300px;border:1px solid red;">
</div>
<span id="showxy"></span>
</body>
案例三:
<script type="text/javascript">
//文字框中輸入一個六位元,第一位不能為0,不能超過六位元,必須全是數字,
var i=0;
function checkNum(obj){
if(i==6){
window.alert("輸入的字串長度>6");
return false;
}
//首位不能是0
if(i==0){
if(window.event.keyCode==‘0‘.charCodeAt(0)){
alert(‘首位不能是0‘);
return false;
}
}
if(window.event.keyCode<‘0‘.charCodeAt(0)||window.event.keyCode>‘9‘.charCodeAt(0)){
alert("你輸入的不是數");
return false;
}else{
i++;
}
}
</script>
</head>
<body>
請輸入一個六位元 <input type="text" id="pageNow" onkeydown="return checkNum(this)"/>
</body>
著作權聲明:博主原創文章,轉載請說明出處。http://blog.csdn.net/dzy21
javascript之dom編程(2):常用對象1