不可勾选的单选按钮与独有的复选框

发布于 2024-11-08 00:45:09 字数 2713 浏览 0 评论 0原文

从 UI 角度来看,是拥有一组具有取消选中功能的单选按钮更好,还是拥有一组独占的复选框(意味着一次只能选中一个)更好?

更新:

我没想到会有如此负面的反应。如果我给出一个更接近其使用方式的示例,也许会有所帮助。

我有一个充满数据绑定内容的 GridView。用户可以选择其中一行作为“主要”行,但这不是必需的。新的例子:

$(":radio").click(function() {
    if (this.previous) {
        this.checked = false;
    }
    this.previous = this.checked;
});

$(":checkbox").click(function() {
    $(":checkbox").not(this).prop("checked", false);
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
Choose a primary city and state (if applicable).<br />
<table><tr><td>
<table border="1" >
<tr><td>Primary</td><td>City</td><td>State</td></tr>
<tr><td><input type="radio" name="radio" /></td><td>Pahokee</td><td>Flordia</td></tr>
<tr><td><input type="radio" name="radio" /></td><td>Palatka</td><td>Flordia</td></tr>
<tr><td><input type="radio" name="radio" /></td><td>Palm Bay</td><td>Flordia</td></tr>
<tr><td><input type="radio" name="radio" /></td><td>Palm Beach Gardens</td><td>Flordia</td></tr></table></td><td>&nbsp;&nbsp;&nbsp;</td><td><table border="1" >
<tr><td>Primary</td><td>City</td><td>State</td></tr>
<tr><td><input type="checkbox" /></td><td>Pahokee</td><td>Flordia</td></tr>
<tr><td><input type="checkbox" /></td><td>Palatka</td><td>Flordia</td></tr>
<tr><td><input type="checkbox" /></td><td>Palm Bay</td><td>Flordia</td></tr>
<tr><td><input type="checkbox" /></td><td>Palm Beach Gardens</td><td>Flordia</td></tr>
</table></td><tr>
</table>

我应该包含一个额外的控件来取消选中“主要”,还是只是扩展 CheckBox 或 RadioButton 的功能?

如果您想到额外的 RadioButton,那么它会放在标题中的哪里?

顺便说一句,由于 ASP.Net 修改了 GroupName,因此看起来需要 JavaScript 才能使 RadioButtons 在 GridView 中工作。

更新 2:

另外,请参阅 ASP.NET AJAX 扩展器 MutuallyExclusiveCheckBox

From a UI prospective, is it better to have a set of RadioButtons with the added functionality of being able to uncheck, or have a set of exclusive CheckBoxes, meaning only one can be checked at a time?

Update:

I did not expect such negative responses to this. Maybe it would help if I gave an example that is closer to how it's being used.

I have a GridView full of databound stuff. The user has the option of choosing one of the rows as "primary", but it's not required. new example:

$(":radio").click(function() {
    if (this.previous) {
        this.checked = false;
    }
    this.previous = this.checked;
});

$(":checkbox").click(function() {
    $(":checkbox").not(this).prop("checked", false);
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
Choose a primary city and state (if applicable).<br />
<table><tr><td>
<table border="1" >
<tr><td>Primary</td><td>City</td><td>State</td></tr>
<tr><td><input type="radio" name="radio" /></td><td>Pahokee</td><td>Flordia</td></tr>
<tr><td><input type="radio" name="radio" /></td><td>Palatka</td><td>Flordia</td></tr>
<tr><td><input type="radio" name="radio" /></td><td>Palm Bay</td><td>Flordia</td></tr>
<tr><td><input type="radio" name="radio" /></td><td>Palm Beach Gardens</td><td>Flordia</td></tr></table></td><td>   </td><td><table border="1" >
<tr><td>Primary</td><td>City</td><td>State</td></tr>
<tr><td><input type="checkbox" /></td><td>Pahokee</td><td>Flordia</td></tr>
<tr><td><input type="checkbox" /></td><td>Palatka</td><td>Flordia</td></tr>
<tr><td><input type="checkbox" /></td><td>Palm Bay</td><td>Flordia</td></tr>
<tr><td><input type="checkbox" /></td><td>Palm Beach Gardens</td><td>Flordia</td></tr>
</table></td><tr>
</table>

Should I include an extra control for unchecking the "primary", or just extend the functionality of the CheckBox or RadioButton ?

If you think extra RadioButton, where would that go, in the header?

BTW, it looks like JavaScript is needed to make RadioButtons work in a GridView anyway because of ASP.Net munging the GroupName.

Update 2:

Also, see ASP.NET AJAX extender MutuallyExclusiveCheckBox

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

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

发布评论

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

评论(4

一曲琵琶半遮面シ 2024-11-15 00:45:09

一定要使用单选按钮,因为它们就是用于此目的的。为什么要让用户对复选框感到困惑,并通过编写代码来维护独占行为进一步给自己带来麻烦呢?

Definitely use radio buttons, as they are meant for this purpose. Why confuse the user with checkboxes and further trouble yourself by writing code to maintain exclusive behaviour?

巡山小妖精 2024-11-15 00:45:09

尽管我不同意更改 radiocheckbox 控件的预期功能,但我也遇到过需要这样做的情况。

如果您使用 Javascript 执行此操作,并且您的用户禁用了 JS,那么它将会严重失败。

appearance CSS 属性是您的朋友。

Though I don't agree with changing the expected functionality of radio and checkbox controls, I have had cases where I needed to.

If you do this with Javascript, it's going to fail spectacularly if your user has JS disabled.

The appearance CSS attribute is your friend.

水中月 2024-11-15 00:45:09

如果用户只能从一组选项中选择一个,请使用单选按钮。如果用户可以选择任意数量的选项,请使用复选框。请注意,“只有一个选择”的定义可以包括一个显示“无”的单选按钮。

自从 GUI 发明以来,这几乎成为每个平台上的标准。偏离这种做法只会让您的用户感到困惑。

If the user can pick only one choice out of a set, use radiobuttons. If the user can pick any number of choices, use checkboxes. Note that the definition of "only one choice" can include a radiobutton that says "none".

That's been the standard on pretty much every platform since GUIs were invented. Deviating from that practice will only serve to confuse your users.

嘦怹 2024-11-15 00:45:09

正如其他人所说,您不应该更改本机表单元素的预期行为。我将使用一组单选按钮,并包含一个用于“清除选择”的按钮。这明确表明选择可清除的,并提供了一种明显的方法来做到这一点。

另一种方法是“发明”一种新型控件 - 可能基于隐藏的单选按钮,也许看起来像一组“切换”。不过,这是一个非常直观的解决方案,并且依赖于 javascript,因此它可能不是最可靠的选择。

这是两种解决方案的示例:
http://www.spookandpuff.com/examples/clearableOptions.html

目前,这两种解决方案依赖 javascript - 通过让清除按钮将表单提供给服务器,并使用清除的单选按钮集进行响应,您可以轻松地为第一个选项提供无 JS 的后备。

Like other people have said, you shouldn't change the expected behaviour of native form elements. I would use a group of radio buttons, and include a button for 'clear selection'. That makes it explicit that the selection is clearable, and provides an obvious way of doing it.

Another way to do it would be to 'invent' a new type of control - probably based on hidden radio buttons, perhaps something that obviously looked like a group of 'toggles'. This is a very visual solution though, and would rely on javascript, so it's probably not the most reliable choice.

Here's an example of both solutions:
http://www.spookandpuff.com/examples/clearableOptions.html

Both solutions are currently javascript reliant - you could easily give the first option a JS-free fallback by having the clear button give the form to the server, and respond with a cleared radio button set.

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