在 HTML 中建立啟用元素的快捷鍵
我們可以設計一個鍵盤快捷鍵來執行某些操作,例如單擊連結或按鈕,以顯示鍵盤文字。在定義元素時,我們可以使用accesskey屬性為該控制元件元素指定鍵盤快捷鍵。
此屬性必須包含至少一個可列印字元,包括可以使用鍵盤輸入的重音/其他字元。
但是,不同的瀏覽器在其平臺上使用不同的方式啟用accesskey -
| Windows | Linux | ||
|---|---|---|---|
| Internet Explorer |
Alt + key Alt + Shift + key |
N/A | |
| Mozilla Firefox |
Alt + Shift + key |
Alt + Shift + key |
|
| Google Chrome |
Alt + key Alt + Shift + key |
Alt + key |
|
| Microsoft Edge |
Alt + key Alt + Shift + key |
N/A | |
| Opera 15+ |
Alt + key |
Alt + key |
|
| Opera 12 | Shift + Esc 開啟可透過 accesskey 訪問的內容列表,然後按相應的鍵 | ||
示例
在下面的示例中,我們使用 accesskey 為元素新增快捷鍵。
<!DOCTYPE HTML> <html> <body> <h1>Use the Shortcut keys to access the Content</h1> <p> Press the <kbd>Alt + W</kbd> keys to navigate the following link : </p> <a href="https://www.youtube.com/" accesskey="w" target="">Open Youtube. </a> <p> Press the <kbd>Alt + Z </kbd>keys to focus on the following text field </p> Enter Your Name : <input type="text" name="name" accesskey="z"> <p> Press the <kbd>Alt+S</kbd> keys to click the button to submit the form: </p> <input type="submit" accesskey="s" onclick="alert('Form submitted successfully.')"> </body> </html>
在執行上述指令碼後,訪問鍵 被觸發並建立了程式碼中提到的快捷鍵。
廣告
資料結構
網路
關係資料庫管理系統
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP