javascript之dom編程(2):常用對象1

來源:互聯網
上載者:User

標籤: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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.