1. 程式人生 > 其它 >設定a標籤,實現點選跳轉頁面

設定a標籤,實現點選跳轉頁面

設定a標籤的屬性target,下面對target屬性進行描述:

跳轉在同一個視窗

1、target="_self", 它使得目標文件載入並顯示在相同的框架或者視窗中作為源文件。(此處就是實現你的每次跳轉都在同一個視窗的核心點)

跳轉在新的視窗

2、target="_blank",瀏覽器總在一個新開啟、未命名的視窗中載入目標文件

總結:屬性值前面都是英文字元的下劃線_ ,別打錯了

方法1:使用onclick事件

<input type="button" value="按鈕"
onclick="javascrtpt:window.location.href='http://www.baidu.com/'" />

或者直接使用button標籤

<button onclick="window.location.href = 'https://www.baidu.com/'">百度</button>

方法2:在button標籤外套一個a標籤

<a href="http://www.baidu.com/">
    <button>百度</button>
</a>

或使用

<a href="http://www.baidu.com/"><input type="button" value='百度'></a>

方法3

:使用JavaScript函式

<script>
function jump(){
 window.location.href="http://www.baidu.com/";
}
</script>
<input type="button" value="百度" onclick=javascrtpt:jump() />
// 或者<input type="button" value="百度" onclick="jump()" />
// 或者<button onclick="jump()">百度</button>

去掉a標籤的下劃線

<style type="text/css">
a{text-decoration:none;}
</style>