」語句設定;2、利用「 」語句用a標籤包裹button元素設定。"/> 」語句設定;2、利用「 」語句用a標籤包裹button元素設定。">

首頁  >  文章  >  web前端  >  html5怎樣設定button按鈕跳轉頁面

html5怎樣設定button按鈕跳轉頁面

WBOY
WBOY原創
2021-12-30 16:37:1211043瀏覽

方法:1.利用「」語句用a標籤包裹button元素設定。

html5怎樣設定button按鈕跳轉頁面

本教學操作環境:windows10系統、HTML5版、Dell G3電腦。

html5怎麼設定button按鈕跳轉頁面

#1、利用onclick點擊事件和window.location.href屬性為按鈕元素新增點擊活動進行跳轉頁面。

語法如下:

<button onclick="window.location.href=跳转地址">按钮</button>

範例如下:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
<button onclick="window.location.href=&#39;https://www.baidu.com/&#39;">按钮</button>
</body>
</html>

輸出結果:

html5怎樣設定button按鈕跳轉頁面

##2、利用a標籤將button元素包裹起來,利用a標籤的href屬性設定跳轉位址即可。

範例如下:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
<a href="https://www.baidu.com/"><button>按钮</button></a>
</body>
</html>

輸出結果與上述結果相同。

推薦教學:《

html影片教學

以上是html5怎樣設定button按鈕跳轉頁面的詳細內容。更多資訊請關注PHP中文網其他相關文章!

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