Js中的bom

來源:互聯網
上載者:User

標籤:one   mil   點擊   tab   資訊   interval   body   als   script   

(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)">

  

 

Js中的bom

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.