html - <optgroup label ='-------' ></optgroup> 给出 xhtml 验证错误

标签 html css optgroup

Error: End tag for 'optgroup' which is not finished. You have probably failed to 
include a required child element. Hence the parent element is "not finished",
 not complete. 

我想在选择选项中实现类似的目标。

USA
UK
--
Afghanistan

我想把几个重要的国家放在最上面,然后是一个不可选择的分隔符,然后是剩余国家的有序列表。

我使用空的“optgroup”放置此分隔线。虽然它在所有浏览器中都能完美运行,但我收到验证错误。

还有什么其他方法可以实现这一点?

最佳答案

与@ZippyV 写的类似,您可以只使用 <option>并将其禁用:

<option disabled='disabled'>--</option>

那将是不可选择的。另外,如果是我,我会使用 m-dash 而不是两个连字符:

<option disabled='disabled'>&mdash;</option>

关于html - <optgroup label ='-------' ></optgroup> 给出 xhtml 验证错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2401437/

相关文章:

jquery - 在 <optgroup> 中显示带有组标签的选定选项

嵌套并设置为 100% 时的 HTML 表格高度,第二个表格与第一个表格重叠

javascript - 如何在不使用 AJAX 或 "Mega Strings"的情况下将大量 HTML 插入 DOM

javascript - 如何解析以下代码中的 "cannot read property appendChild of null"?

jquery - 向左切换菜单

css - Vaadin 菜单栏,元素的标题和图标之间的空间

jquery - 如何使用 css 或 jquery 定位 optgroup 的第一个 child

html - 如何将我自己的图像添加到链接到 HTML 和 CSS 中另一个网站的按钮?

javascript - 使用关闭操作在输入中添加关闭图标