首頁  >  文章  >  web前端  >  html/JavaScript怎麼跳頁

html/JavaScript怎麼跳頁

青灯夜游
青灯夜游原創
2021-04-12 17:54:143238瀏覽

跳轉頁面的方法:1、html中可以利用meta標籤進行跳轉,語法「」;2、javascript中可以利用location物件的href屬性進行跳轉,語法「window. location.href=頁面位址」。

html/JavaScript怎麼跳頁

本教學操作環境:windows7系統、javascript1.8.5版、Dell G3電腦。

html/JavaScript實作頁面跳轉

1、html中使用meta中跳轉,透過meta可以設定跳轉時間和頁面

<head>
    <!--只是刷新不跳转到其他页面 -->
    <meta http-equiv="refresh" content="5">
    <!--定时转到其他页面 -->
    <meta http-equiv="refresh" content="5;url=index.html"> 
</head>

2、透過javascript實現跳轉

1 // 直接跳转
2 window.location.href='index.html';
3 // 定时跳转
4 setTimeout("javascript:location.href='index.html'", 5000);

html跳轉上一頁的方式

window.history.go(-1);或window.history .back(-1);

<script type="text/javascript">
    var wrong = document.getElementById('btn');
    wrong.onclick = function() { 
    window.history.go(-1);//返回上一页
     window.history.back(-1);//返回上一页
   }
</script>

在html中寫

<a href=”#” onClick=”JavaScript :history.back(1);”>返回上一页</a>
<a href=”#” onClick=”javascript :history.Go(-1);”>返回上一页</a>

【推薦學習:javascript高階教學

#

以上是html/JavaScript怎麼跳頁的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn