无线电组中的一个HTML单选按钮是否应该始终被检查? [英] Should One HTML Radio Button In a Radio Group Always Be Checked?

查看:113
本文介绍了无线电组中的一个HTML单选按钮是否应该始终被检查?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

我遇到了业务需求,我被问到组中的两个单选按钮都未被选中,然后有逻辑强制用户选择一个,然后才能继续。



虽然我知道如何达到这个目标,但我感觉不对,而且我也是这样暗示的,但是正在寻找更明确地规定这一点的准则,所以我可以将其纳入我们自己的标准。

解决方案

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


在任何时候,一组中的一个单选按钮被选中。如果一组单选按钮中没有一个指定了CHECKED,那么用户代理必须首先检查该组的第一个单选按钮。


该规范使用术语user agent来表示通常称为浏览器的内容。 因此,规范说,如果没有选中,浏览器会检查第一个。 >请注意,我试过的4个浏览器实际上都没有这样做!他们没有检查第一个, none 的收音机是以 = on 到服务器。一个好的Web框架应该做服务器端检查(它应该这样做,因为中断或伪造的POST可能导致相同的问题)。


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.

解决方案

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).

这篇关于无线电组中的一个HTML单选按钮是否应该始终被检查?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆