如何在 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>
廣告