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