設置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>