Why the select tag need at least on child to be xhtml 1.0 valid
Why the select tag need to have at least on child to be valid xhtml 1.0 ?
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>Why select tag need at least one child to be xhtml valid ?</title>
</head>
<body>
Allowed users :<br/>
<select size="5" style="width: 200px">
</select>
<br />
Alls users :<br/>
<select size="5" style="width: 200px">
<option>root</option>
<option>John Doe</option>
<option>Jane Doe</option>
</select>
</body>
</html>
To be valid, I need to write :
<select><option/></select>
I think it's useless and it's cumbersome to add the empty option tag programmatically (especially in ASP.NET WebForms, I use a DropDownList or List开发者_如何学GoBox control with a dataBind) :
if count == 0 then add <option/>...
There is no explanation in the DTD : http://www.w3.org/TR/xhtml1/dtds.html
Do you know why W3C validation require that ?
(And how can I make this page valid using a DropDownList or ListBox control in ASP.NET WebForms 4.0 ?)
Assuming that the reason this is an issue is because you are adding the option
s dynamically, I would suggest that also add the select
dynamically, too.
In fact, you could add a node
on page load...
<a name="whatever" id="whatever-id" />
and replace it with a select
and options
when necessary.
What would be the semantic meaning of a select without any options? You might as well not have a select...
Why? Most likely because its a standard defined approximately 10 years ago. You should consider moving on...
Example below.
HTML5
Switch your doctype line to:
<!DOCTYPE html>
And your meta charset line to:
<meta charset="UTF-8" />
Resulting HTML Markup:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="UTF-8" />
<title>Why select tag need at least one child to be xhtml valid ?</title>
</head>
<body>
Hello World : <select></select>
</body>
</html>
Feel free to validate in http://validator.w3.org/#validate_by_input
精彩评论