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