并<选择>标签

发布于 2024-08-06 21:31:03 字数 262 浏览 2 评论 0原文

我可以在 HTML

例如:

<select tabindex="2" name="agegrp" id="agegrp" >
    <div> 
        <option value="-1">No preference</option>
    </div>
</select>

Can I have a <DIV> within an HTML <SELECT> tag?

e.g.:

<select tabindex="2" name="agegrp" id="agegrp" >
    <div> 
        <option value="-1">No preference</option>
    </div>
</select>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

北陌 2024-08-13 21:31:03

规范

<!ELEMENT SELECT - - (OPTGROUP|OPTION)+ -- option selector -->

即有一个名为“ SELECT”,开始标记是必需的,结束标记是必需的。它的子元素可以是 OPTGROUP 元素和/或 OPTION 元素,并且必须至少有其中之一。

由于 DIV 不是 OPTGROUP 或 OPTION,所以答案是

From the specification:

<!ELEMENT SELECT - - (OPTGROUP|OPTION)+ -- option selector -->

i.e. There is an element called "SELECT", the start tag is required, the end tag is required. It's children can be OPTGROUP elements and/or OPTION elements and there must be at least one of them.

Since a DIV is not an OPTGROUP or an OPTION, the answer is no.

凹づ凸ル 2024-08-13 21:31:03

不,不。尼特。

No. Nope. Niet.

携余温的黄昏 2024-08-13 21:31:03

No, but you may be interested in the optgroup element. Be aware that its appearance tends to vary a lot across different browsers before you start building designs around it though.

时常饿 2024-08-13 21:31:03

不,也没有理由这样做。

No. And there is no reason to.

晨光如昨 2024-08-13 21:31:03

虽然您可以生成任何您想要的疯狂 HTML,但不建议使用 DIV。通过引入 DIV 您试图解决的问题是什么

也许您不知道 OPTGROUP 标记?

标签用于分组
将相关选项放在选择中
列表。

如果您有一长串选项,
相关选项组更容易
为用户处理。

While you can generate any crazy HTML you want, that is not a recommended use of DIV. What is the problem you are trying to solve by introducing the DIV?

Perhaps you are unaware of the OPTGROUP tag?

The tag is used to group
together related options in a select
list.

If you have a long list of options,
groups of related options are easier
to handle for the user.

芸娘子的小脾气 2024-08-13 21:31:03

正如每个人所说,没有必要在选择列表中执行 div。如果您需要单独移动表单 ID 中的列表元素,建议使用单选按钮。

As everyone has stated there would be no need to do a div within a select list. if you need to individually move list elements in a form id suggest using radio buttons.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文