HTML 单选按钮:隐藏项目符号
我想要一个特定的表单组件充当单选按钮(一次只能选择一个选项)。然而,我不希望显示无线电项目符号,而是选择其他演示方法,例如选择高光或其他一些方法。这将允许优雅的降级:如果用户浏览器不支持 Javascript,它只会降级为基本的单选按钮。我希望通过 Javascript 或 CSS 隐藏项目符号按钮。有人知道怎么做吗?谢谢。
I want a particular form component to act as radio buttons (only one option may be selected at a time). I do not want the radio bullets to show, however, opting for alternative presentational methods such as high light selected, or some other method. This will allow for graceful degradation: if the user browser does not support Javascript it will just degrade to basic radio buttons. I am wish to hide the bullet buttons through Javascript or CSS. Anyone know how? thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
我有一个简单的解决方案,我的单选按钮周围有一个标签,其中的图像代表所选择的内容:
然后我应用了以下样式:
本质上每个
label
都变成了一个常规大小的框,完全由img
填充。无线电本身使用opacity:0
隐藏。用户可以知道所选择的内容,因为选中的单选按钮旁边的img
将是不透明的,而其他单选按钮则是半透明的。你可以很容易地做出各种其他类型的效果。我喜欢的是表单仍然易于处理,它只是一组单选按钮。
我对单选按钮使用了不透明度,而不是
display:none
或visibility:hidden
,因为它们仍然在 tabindex 中,并且表单仍然可以通过键盘访问。I've got a simple solution working where I have a label surrounding my radio buttons with an image representing the thing being selected:
I have then applied the following styles:
Essentially each
label
becomes a regular sized box that is completely filled by animg
. The radio itself is hidden usingopacity:0
. The user can tell what is selected as theimg
next to the checked radio will be opaque whereas the others are semi-transparent. You could do various other kind of effects pretty easily.The thing I like is that the form remains simple to process, it is just a group of radio buttons.
I used opacity for the radio buttons rather than
display:none
orvisibility:hidden
as then they are still in the tabindex and the form remains keyboard accessible.只需隐藏单选按钮(当然不会失去可访问性)就可以使用以下 CSS 来完成:
使用
opacity: 0;
并不理想,因为按钮仍然存在,占用空间页面中的空间。将其放置在视线之外是正确的方法。Just the bit of hiding the radio buttons (without losing accessibility, of course) can be done with the following CSS:
Using
opacity: 0;
isn't ideal, as the button is still there, taking up space in the page. Positioning it out of view is the way to go.如果我理解正确的话,您需要单选按钮,但不希望按钮本身出现。请记住,仅删除按钮不会提供您想要的用户体验。您需要某种形式的用户反馈。
您有两个选择:
1)使用 javascript / jquery 进行编程。考虑到这一点,我建议您使用单选按钮作为起始占位符,然后使用 javascript(最好通过 jquery 插件),它将重绘页面并用可点击的 div 和动态更改的隐藏字段值替换按钮。
2)使用 CSS 元类 :checked 不幸的是似乎没有跨浏览器支持。
If I understand this correctly, you want radio buttons but you don't want the buttons themselves to appear. Keep in mind that just removing the buttons will NOT provide the user experience you are looking for. You need to have some form of user feedback.
You have two options:
1) Program this using javascript / jquery. With that in mind I would suggest you use radio buttons as a starting placeholder, and then use javascript (ideally via a jquery plugin) which will redraw the page and replace the buttons with clickable divs and a dynamically changing hidden field value.
2) Use the CSS meta class of :checked which unfortunately doesn't appear to have cross browser support.
或者,如果您的浏览器支持(
文档中的querySelectorAll
)...Alternatively, if your browser supports it (
querySelectorAll in document
)...我不认为你可以用CSS隐藏它。您必须隐藏单选按钮,然后用 JS 替换该功能。也许可选的 LI 列表适合您。
从 jQuery UI 可选择: http://jqueryui.com/demos/selectable/
I don't think you can hide it with css. You'd have to hide the radiobuttons and then replace the functionality with JS. maybe a selectable list of LIs would work for you.
From the jQuery UI Selectable : http://jqueryui.com/demos/selectable/
您可以通过添加此 style="list-style:none;" 来做到这一点
you can do it by adding this style="list-style:none;"
只需插入:
样式=“显示:无;”
在每个
""
标记内。这使得项目符号不可见,但使标签显示。
Just insert:
style="display:none;"
inside every
"<input type='radio'…>"
tag.This makes the bullets invisible, but leaves the labels showing.