是否应始终选中单选组中的一个 HTML 单选按钮?

发布于 2024-09-14 00:57:42 字数 193 浏览 2 评论 0原文

是否有任何标准(HTML、UI、可访问性等)规定应始终选择给定的一组单选按钮中的一个单选按钮?

我遇到了一项业务需求,要求我将一组中的两个单选按钮保留为未选中状态,然后使用逻辑强制用户选择一个按钮才能继续。

虽然我知道如何实现这一点,但感觉不对,我也这样暗示过,但我正在寻找更明确地规定这一点的指导方针,以便我可以将其纳入我们自己的标准中。

Are there any standards (HTML, UI, accessibility, and such like) that stipulate that one of the radio buttons in a given group of radio buttons should be selected at all times?

I have encountered a business requirement whereby I have been asked that both radio buttons in a group be left unchecked, and then to have logic forcing the user to select one before they can continue.

While I know how to achieve this, it felt wrong, and I intimated as such, but was looking for guidelines that stipulate this more explicitly so I can feed this into our own standards.

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

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

发布评论

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

评论(5

來不及說愛妳 2024-09-21 00:57:43

我本来想说我过去读过雅各布·尼尔森的一些东西,但是哎呀,我发现了它:
附言。就我个人而言,我总是默认选择一个,所以对于选择框,但发生的情况是在法律条款和条件下,律师们很害怕,当然,你把猫喂给你的狗,你将永远害怕小猫:

始终提供默认选择
单选按钮列表。根据定义,
单选按钮始终只有一个
选择了选项,因此您
不应该在没有
默认选择。 (复选框,在
相比之下,通常默认为没有
所选选项的数量。) ◦如果用户
可能需要避免
选择时,您应该提供收音机
用于此选择的按钮,例如
标记为“无”。为用户提供
明确的、中立的点击选项是
比要求隐性行为更好
不从列表中选择,
尤其是因为

http://www.useit.com/alertbox/20040927.html

I was going to say I read something in the past by Jakob Neilson, but heck, I found it:
PS. personally I ALWAYS have one selected by default, and so for select boxes, but what happens is in legal terms and conditions, lawyers are afraaaaid, of course, you feed the cat to your dog you will always be afraid of the kittens :

Always offer a default selection for
radio button lists. By definition,
radio buttons always have exactly one
option selected, and you therefore
shouldn't display them without a
default selection. (Checkboxes, in
contrast, often default to having none
of the options selected.) ◦If users
might need to refrain from making a
selection, you should provide a radio
button for this choice, such as one
labeled "None." Offering users an
explicit, neutral option to click is
better than requiring the implicit act
of not selecting from the list,
especially because

http://www.useit.com/alertbox/20040927.html

蒗幽 2024-09-21 00:57:43

标准并不总是有意义

如果您遵循其他答案所述的标准(尼尔森所做的),则应始终选中一个单选按钮。

但如果您遵循常识并针对用例进行设计,那么答案是显然不是。天知道什么原因该标准完全忽略了一个非常流行的用例:

用户应做出排他性选择,但不得存在默认情况。

也许一个典型的例子是李克特量表 - 任何默认值都会吸引参与者:

A Likert survery

现代语言示例

您会如何将以下问题翻译为接口:

您想喝茶还是咖啡?

该标准迫使你这样问:

您想要茶还是咖啡?我相信你想要的是茶。

因此没有人遵守它们

正是因为该标准没有考虑到这种情况(以及替代方案缺乏可用性,例如带有空白选项的组合框),所以没有浏览器遵守该标准 - 想象一下带有单选按钮的 Google 表单有默认值。

Standards don't always make sense

If you follow the standard (which is what Neilson does) that as other answers state - than one radio button should always be checked.

But if you follow common sense, and design for use cases than the answer is clearly not. For god knows what reason the standard completely neglects a very popular use case:

The user shall make an exclusive choice, but no default shall exist.

Perhaps a prime example for this is likert scales - any default will prime participants:

A likert survery

A modern language example

How would you translate to an interface the following question:

Would you like tea or coffee?

The standard forces you to ask it this way:

Would you like tea or coffee? I believe it's tea that you want.

And so no one comply with them

It is exactly because the standard doesn't account for such cases (and the lack of usability in alternatives, like comboboxes with a blank option) that no browser comply with the standard - Imagine Google Forms with radio buttons having a default.

风和你 2024-09-21 00:57:43

任何时候你重写默认的浏览器行为都会给用户带来不确定性。此外,平均而言,当有两个选项时,预先选择的选项正确的可能性为 50%。强迫用户选择它只会减慢他们的速度,因为他们假设他们要么是盲目的,要么是无能的。

我个人认为这个概念是侮辱性的——但我不是经理。

Anytime you're overriding a default browser behaviour you're creating uncertainty for the user. Furthermore, on average, when there are two options there is a 50% chance that the pre-selected one will be correct. Forcing the user to select it just slows them down on the assumption they're either blind or clueless.

I would personally find the concept insulting - but then I'm not a manager.

酷到爆炸 2024-09-21 00:57:43

一个很好的例子是,当您拥有一家网上商店,并希望客户做出主动选择,而不是让某些订单通过时,客户只需单击“添加到购物车”而不选择任何尺寸,从而获得预先选择的尺寸。

我错了吗?

One good example is when you have a webshop and want the customer to make an active choice instead of letting some orders through where the customer just clicked on add to cart without choosing any size and therefore get the size that is pre selected.

Am I wrong?

月朦胧 2024-09-21 00:57:42

是:http://www.w3.org/TR/html401/interact /forms.html#radio

任何时候,都会选中一组单选按钮中的一个。如果一组单选按钮中没有一个元素指定“CHECKED”,则用户代理必须首先检查该组单选按钮的第一个单选按钮。

该规范使用术语“用户代理”来表示通常所说的“浏览器”。 所以规范说,如果没有检查,浏览器将检查第一个。

更新: 请注意,我尝试过的 4 个浏览器实际上都没有这样做!< /em> 他们不检查第一个无线电,并且没有无线电作为=on 提供给服务器。一个好的 Web 框架应该进行服务器端检查(无论如何它都应该这样做,因为突然或伪造的 POST 可能会导致同样的情况)。

Yes: http://www.w3.org/TR/html401/interact/forms.html#radio

At all times, exactly one of the radio buttons in a set is checked. If none of the elements of a set of radio buttons specifies `CHECKED', then the user agent must check the first radio button of the set initially.

The specification uses the term "user agent" for what is commonly known as "browser". So the specification says that if none is checked, the browser will check the first.

UPDATE: note that none of the 4 Browsers i tried actually does this! They dont check the first and none of the radios are given as =on to the server. A good web framework should do the serverside-checking (it should do it anyway because an abrupted or forged POST could cause the same).

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