方法:1、利用“<button onclick="window.location.href=跳轉地址">”語句設置;2、利用“<a href=跳轉地址><button>按鈕</button></a>”語句用a標簽包裹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='https://www.baidu.com/'">按鈕</button> </body> </html>
輸出結果:
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視頻教程》