Computer >> Hướng Dẫn Máy Tính >  >> Lập Trình >> HTML

Thuộc tính checked của thẻ <input> trong HTML


Thuộc tính checked của <input> (type="checkbox" hoặc "radio") chỉ định ô được chọn mặc định khi trang tải.

Cú pháp

<input type="checkbox" checked>

Ví dụ: Form đăng ký với checkbox mặc định chọn

<!DOCTYPE html>
<html>
<body>
  <h2>Register</h2>
  <form action="" method="get">
    Id: <input type="text" name="id" placeholder="Enter UserId..." size="25"><br>
    Password: <input type="password" name="pwd" placeholder="Enter password..."><br>
    DOB: <input type="date" name="dob" placeholder="Enter date of birth..."><br>
    Telephone: <input type="tel" name="tel" placeholder="Enter mobile number..."><br>
    Email: <input type="email" name="email" placeholder="Enter email..." 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>

Checkbox "Newsletter Subscription" sẽ được tích sẵn khi trang load nhờ thuộc tính checked.