Checkbox checkedProperty

Checkbox 对象参考手册Checkbox Object

Definition and Usage

The checked property sets or returns whether a checkbox should be checked.

Syntax

Set the checked property:

checkboxObject.checked=true|false

Return the checked property:

checkboxObject.checked


Browser Support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support the checked property


Examples

Examples

The following example can set the state of the checkbox:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Rookie Tutorial (example.com)</title>
<script>
function check(){
    document.getElementById("check1").checked=true
}
function uncheck(){
  document.getElementById("check1").checked=false
}
</script>
</head>
<body>

<form>
<input type="checkbox" id="check1">Do you like summer?
</form>
<button onclick="check()">Check checkbox</button>
<button onclick="uncheck()">Uncheck checkbox</button>

</body>
</html>

Try it Yourself »


实例s

More Examples

Checkbox - Convert text to uppercase

Several checkboxes in a form


Checkbox 对象参考手册Checkbox Object Other extensions