HTMLchecked 属性
<input>元素的 checked 属性指定在加载网页时,输入类型复选框已选中。还可以将此属性用于输入类型单选按钮。
以下是语法 −
<input type=”checkbox” checked>
以上,我们已将其设置为 checked,因为我们希望在加载网页时选中复选框。
现在让我们看一个示例来实现 <input> 元素的 checked 属性 −
示例
<!DOCTYPE html> <html> <body> <h2>Register</h2> <form action = "" method = "get"> Id: <input type = "text" name = "id" placeholder = "Enter UserId here..." size = "25"><br> Password: <input type = "password" name = "pwd" placeholder = "Enter password here..."><br> DOB: <input type = "date" name = "dob" placeholder = "Enter date of birth here..."><br> Telephone: <input type = "tel" name = "tel" placeholder = "Enter mobile number here..."><br> Email: <input type = "email" name = "email" placeholder = "Enter email here..." size = "35"><br><br> <input type = "checkbox" name = "vehicle" value = "Bike" checked>Newsletter Subscription: <br> <button type = "submit" value = "Submit">Submit</button> </form> </body> </html>
输出

在以上示例中,我们有一个带有按钮的表单 −
<form action = "" method = "get"> Id: <input type = "text" name = "id" placeholder = "Enter UserId here..." size = "25"><br> Password: <input type = "password" name = "pwd" placeholder = "Enter password here..."><br> DOB: <input type = "date" name = "dob" placeholder = "Enter date of birth here..."><br> Telephone: <input type = "tel" name = "tel" placeholder = "Enter mobile number here..."><br> Email: <input type = "email" name = "email" placeholder = "Enter email here..." size = "35"><br><br> <input type = "checkbox" name = "vehicle" value = "Bike" checked>Newsletter Subscription: <br> <button type = "submit" value = "Submit">Submit</button> </form>
除此之外,我们还设置了一个复选框 −
<input type="checkbox" name="vehicle" value="Bike" checked>Newsletter Subscription:
如上所见,我们设置了 checked 属性,以便在加载页面时,输入类型复选框保持选中状态。
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP