如何在HTML中指定一個頁面載入時元素應被預先選中?
使用checked屬性指定<input>元素應在頁面載入時被預先選中。該屬性適用於 -
<input type = "checkbox"> <input type = "radio">.
示例
你可以嘗試執行以下程式碼來在 HTML 中實現checked屬性 -
<!DOCTYPE html> <html> <body> <p>Which sports do you like?</p> <form action = "" method = "get"> <input type = "checkbox" name = "vehicle" value = "football" checked> Football<br> <input type = "checkbox" name = "vehicle" value = "cricket" checked> Cricket<br> <input type = "checkbox" name = "vehicle" value = "hockey"> Hockey<br> <input type = "submit" value = "Submit"> </form> </body> </html>
廣告