<标签>关于复选框:是否有更多网站不使用它的原因?

发布于 2024-07-11 03:22:50 字数 756 浏览 6 评论 0原文

我总是尝试执行以下操作:

<label><input type="checkbox" /> Some text</label>

或者

<label for="idOfField"><input type="checkbox" id="idOfField" /> Some text</label>

我的问题与标签标记相关,特别是在复选框上。

大多数网站(我想说 >40%)不使用 标签。

是否有一个原因? 是浏览器有问题还是其他问题?

注意:如果人们不知道标签,它有很多优点:

  • 复选框和标签。 收音机:您可以单击文本以及复选框来选中复选框(以及我相信的焦点):Blah blah blah
  • 其他输入:如果您单击文本,它将聚焦输入(文本区域、文本、文件) (此功能不如复选框和单选按钮有用)

注释 2: 有些人提到示例 #2 比示例 #1(上面)更正确,但根据文档 此处,任一正确

I always try to do the following:

<label><input type="checkbox" /> Some text</label>

or

<label for="idOfField"><input type="checkbox" id="idOfField" /> Some text</label>

My question is related to the label tag, specifically on a checkbox.

Most websites (I would say >40%) don't use the <label> tag.

Is there a reason for this? Is there a problem in a browser or some other issue?

Note: Incase people don't know about the <label> tag, it has a number of advantages:

  • checkboxes & radios: you can click on the text as well as the checkbox to check the checkbox (as well as focus I believe): Blah blah blah
  • other inputs: if you click the text, it will focus the input (textarea, text, file) (this functionality isn't as useful as checkboxes & radios)

Note 2: Some people have mentioned that example #2 is more correct than #1 (above), but according to the documentation here, either is correct

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

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

发布评论

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

评论(8

偏爱自由 2024-07-18 03:22:51

某些较旧的浏览器不解释 for 属性,而是要求将表单元素嵌套在 label 标记内。

Some older browsers don't interpret the for attribute, and instead require the form element to be nested within the label tag.

只为一人 2024-07-18 03:22:51

在网站上工作的开发人员不知道 标签的存在。

The developer working on the site didn't know the <label> tag existed.

孤凫 2024-07-18 03:22:51

大多数网站都是由那些只做让网站按照他们认为应该的方式工作的人创建的。 处理流程是:

  1. 尝试一下。
  2. 在浏览器中加载它,看看有什么问题。
  3. 在谷歌上搜索修复程序。
  4. 重复。

由于这些人中的大多数人从未尝试在不使用鼠标的情况下集中任何输入,因此问题永远不会变得明显。

Most web sites were made by people who only do what it takes to get the site to work like they think it should. Process flow is:

  1. Take a stab at it.
  2. Load it in browser, and see what's wrong.
  3. Search google for the fixes.
  4. Repeat.

Since most of these people never try to focus any inputs without using the mouse, the problem never becomes evident.

南城追梦 2024-07-18 03:22:51

优点是显而易见的,但我认为大多数人都不知道它,因为标签似乎没有传达任何具体信息。 您可以明显看到使用强标签的优势,因为它使文本看起来粗体,但标签标签呢? 你不会注意到有什么不同。

The advantages are obvious but I don't think most know about it because label seems to convey nothing concrete. You can obviously see the advantage of using a strong tag because it makes the text look bold but label tag? You wouldn't notice anything different.

往日情怀 2024-07-18 03:22:51

因为这是一个被低估的标签,应该得到更多关注。 当您使用它(提高可访问性)时,不要忘记 tabindex 属性。

Because it's an underhyped tag that should get more attention. While you're at it (improving accessibility), don't forget the tabindex property.

错爱 2024-07-18 03:22:50

我认为这可能是人们不了解

I think it's probably more a factor that people don't know about the <label> tag. I didn't, until this post.

倾其所爱 2024-07-18 03:22:50

我同意标签通常是未知的标签。
我在表单中使用它

<label for="chk1">Some text</label><input id="chk1" type="checkbox"/>

for 属性让用户单击标签也可以选择具有相应 id(不是名称)的复选框,并且不会被 annidate 我可以更好地使用 CSS 控制布局。

不过我会尝试你的解决方案

I agree that label is often an unknown tag.
I use it in the form

<label for="chk1">Some text</label><input id="chk1" type="checkbox"/>

The for attribute let the user click on the label also to select the checkbox with the corresponding id (not name) and not being annidate I can better control the layout with CSS.

I will try your solution, though

筱果果 2024-07-18 03:22:50

据我所知,使用 没有任何缺点。 过去几年我经常使用它。

实际上有 3 种方法可以设置标签,前两种与您在问题中给出的方法相对应:

<label for="xa">XA: <input type="text" id="xa" /></label><br />
<label for="xb">XB:</label> <input type="text" id="xb" /><br />
<label>XC: <input type="text" id="xc" /></label>

上述所有 3 种方法都适用于 FF3 和 IE7。 我记得出于某种原因,我在心里将最后两个标记为“要避免,只能部分工作”。 因此我敢打赌只有第一个可以在 IE6 中运行。

澄清一下:“最好”的方法是我的示例#1,你的示例#2。

There is no downside to using <label> that I know of. I 've used it a lot in the past few years.

There are actually 3 ways you can set a label, the first two correspond with the ones you gave in your question:

<label for="xa">XA: <input type="text" id="xa" /></label><br />
<label for="xb">XB:</label> <input type="text" id="xb" /><br />
<label>XC: <input type="text" id="xc" /></label>

All 3 of the above work in FF3 and IE7. I remember that for some reason I mentally marked the last two as "to be avoided, only partially work" though. Therefore I 'd bet good money that only the first one works in IE6.

To clarify: the "best" way to do it is my example #1, your example #2.

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