对于具有boolean值的属性,例如disabled与readonly等,但只写属性而不指定属性值时,表示属性值为true;如果想要将属性值设为false,可以不使用该属性。另外,想要将属性值设定为true时,也可以将属性名设定为属性值,或将空字符串设定为属性值。
例如:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>HTML5之具有boolean值的属性</title>
</head>
<body>
<!-- 只写属性不写属性值代表属性为true -->
<input type="checkbox" checked>
<!-- 不写属性代表属性为false -->
<input type="checkbox">
<!-- 属性值=属性名,代表属性为true -->
<input type="checkbox" checked='checked'>
<!-- 属性值=空字符串,代表属性为true -->
<input type="checkbox" checked=''>
</body>
</html>