当页面以HTML加载时,如何指定应预先选择 元素?
使用checked属性可以指定要在页面加载时预先选择的<input>元素。该属性适用于-
<input type = "checkbox"> <input type = "radio">.
示例
您可以尝试运行以下代码以在HTML中实现选中的属性-
<!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>