这是一个简单的 HTML 复选框输入元素:
<input type="checkbox" id="c1">I am a checkbox</input>
但是单击文本不会选中复选框,而是使用标签元素解决:
<input type="checkbox" id="c1"/><label for="c1">I am a checkbox</label>
所以我的问题是复选框文本有什么用?
复选框文本有什么用?
没有。HTML 无效。的结束标签<input>
是禁止的。该input
元素被定义为 EMPTY 并且不能有任何子节点。
您的第一个示例不是有效的 HTML。该<input>
标签是自动关闭的,即<input />
很好<input>
,但<input></input>
不是。
您可以通过将以下代码粘贴到HTML 验证器中来检查这一点。
<!DOCTYPE html>
<html>
<head>
<title>Test</title>
</head>
<body>
<input type="checkbox" id="c1">I am a checkbox</input>
</body>
</html>