发布于 2024-10-08 02:59:44 字数 591 浏览 0 评论 0原文

我在页面中有一个表格,其中包含左侧单元格中的复选框和右侧单元格中的描述。 “描述”包含 h4 标题和纯文本。我想将整个描述( 内的所有内容)作为一个标签。

所以每一行看起来像这样:

<tr><td><input type="checkbox" name="entiries[]" value="i1" id="i1"></td>
<td><label for="i1">
<h4>Some stuff</h4>more stuff..
<h4>Some stuff</h4>more stuff..
</label>
</td></tr>

但是,这不起作用,文本不像标签一样并且不可单击。我正在使用 Firefox 3.6 来测试它。如果我删除

标签,它就会开始工作,但这会使格式变得复杂。 标签是否存在阻止 正常工作的情况?

I have a table in a page that consists of checkboxes in the cells on the left and descriptions in the cells on the right. The "description" contains h4 headers and plain text. I want to make that whole description (everything inside <td></td>) a label.

So each row looks like this:

<tr><td><input type="checkbox" name="entiries[]" value="i1" id="i1"></td>
<td><label for="i1">
<h4>Some stuff</h4>more stuff..
<h4>Some stuff</h4>more stuff..
</label>
</td></tr>

This does not work however, the text does not act like a label and is not clickable. I'm using Firefox 3.6 to test it. If I remove <h4> tags it starts working, but that complicates formatting. Is there something about <h*> tags that prevents <label> from working correctly?

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

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

发布评论

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

评论(4

最初的梦 2024-10-15 02:59:45

块级元素(h4 所属)不允许出现在内联元素中,并且会导致未定义的行为。您可以改用 span 元素。

Block level elements (to which h4 belongs) are not allowed inside inline elements, and will cause undefined behaviour. You can use span elements instead.

皇甫轩 2024-10-15 02:59:45

内联元素(其他标签元素除外)可能出现在标签内元素。

<!ELEMENT LABEL - - (%inline;)* -(LABEL) -- form field label text -->

http://www.w3.org/TR/ html4/interact/forms.html#h-17.9.1

无论如何,将标题放在那里是没有意义的。

Only inline elements (except other label elements) may appear inside label elements.

<!ELEMENT LABEL - - (%inline;)* -(LABEL) -- form field label text -->

http://www.w3.org/TR/html4/interact/forms.html#h-17.9.1

It doesn't make sense to put headings there anyway.

天荒地未老 2024-10-15 02:59:45

HTML 中的 元素是内联级元素,不能包含块级元素。

这可能就是导致您出现问题的原因。或者,您可以将标签放在

中:

<tr><td><input type="checkbox" name="entiries[]" value="i1" id="i1"></td>
<td><
<h4><label for="i1">Some stuff</label></h4>more stuff..
<h4><label for="i1">Some stuff</label></h4>more stuff..
</label>
</td></tr>

The <label> element in HTML is an inline level element and cannot contain block level elements.

This is probably what's causing your issues. Alternatively you can put your labels inside the <h4>'s :

<tr><td><input type="checkbox" name="entiries[]" value="i1" id="i1"></td>
<td><
<h4><label for="i1">Some stuff</label></h4>more stuff..
<h4><label for="i1">Some stuff</label></h4>more stuff..
</label>
</td></tr>
記柔刀 2024-10-15 02:59:45

在 MDN 上,他们准确解释了为什么不在内部使用标题标签标签

将标题元素放入其中会干扰多种辅助技术,因为标题通常用作导航辅助。如果需要在视觉上调整标签的文本,请改用应用于元素的 CSS 类。

Here on MDN they explain exactly why NOT to use headings inside a label tag:

Placing heading elements within a interferes with many kinds of assistive technology, because headings are commonly used as a navigation aid. If the label's text needs to be adjusted visually, use CSS classes applied to the element instead.

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