How do you make an HTML Radio button bold on select?(如何在选择时使 HTML 单选按钮变为粗体?)
问题描述
在 HTML 中,我有以下单选按钮选项
In HTML, I have the following radio button choices
o 选择 1
o 选择 2
o 选择 3
o Choice 1
o Choice 2
o Choice 3
我想要做的是,当有人从上方选择一个单选按钮时,与所选单选按钮对应的文本变为粗体.
What I would like to do is when someone SELECTs a radio button from above, that the text corresponding to that radio button selected becomes bold.
因此,例如 - 如果该人选择选择 2",则单选按钮选择现在看起来像:
So, for example - if the person selects "Choice 2", the radio button selection would now look like:
o 选择 1
o 选择 2
o 选择 3
o Choice 1
o Choice 2
o Choice 3
我该怎么做?我假设必须使用 JavaScript 或 CSS.
How do I do this? I assume either JavaScript or CSS has to be used.
提前致谢
更新:如果不使用 jQuery,你将如何实现nickf"解决方案?
推荐答案
你可以纯粹用 CSS 来做到这一点,但你需要将每个输入的文本包装在 span 或其他标签中:
You can do this purely with CSS, but you need to wrap the text of each input in a span or other tag:
<input type="radio" name="group1" value="Milk"><span>Milk</span><br>
然后只使用兄弟选择器:
Then just use the sibling selector:
input[type="radio"]:checked+span { font-weight: bold; }
这篇关于如何在选择时使 HTML 单选按钮变为粗体?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在选择时使 HTML 单选按钮变为粗体?


- 如何使用 JSON 格式的 jQuery AJAX 从 .cfm 页面输出查 2022-01-01
- Fetch API 如何获取响应体? 2022-01-01
- 失败的 Canvas 360 jquery 插件 2022-01-01
- CSS媒体查询(最大高度)不起作用,但为什么? 2022-01-01
- Flexslider 箭头未正确显示 2022-01-01
- 400或500级别的HTTP响应 2022-01-01
- addEventListener 在 IE 11 中不起作用 2022-01-01
- Css:将嵌套元素定位在父元素边界之外一点 2022-09-07
- Quasar 2+Apollo:错误:找不到ID为默认的Apollo客户端。如果您在组件设置之外,请使用ProvideApolloClient() 2022-01-01
- 使用RSelum从网站(报纸档案)中抓取多个网页 2022-09-06