radio选中状态对应文字改变颜色

本文介绍如何通过CSS样式和jQuery JavaScript库实现单选按钮(radio)被选中时,与其相关联的文字颜色变化效果。通过监听radio的change事件,可以动态更新文字的CSS属性,达到视觉反馈的目的。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

效果:

html:

<input type="radio" class="radio" name="apply" value="" checked="checked" />
<lable class="radio-font" for="apply">本人申请</lable>
<input type="radio" class="radio" name="apply" value="" />
<label class="radio-font" for="apply">代替他人申请</label>
css:

.radio {
	width: 18px;
	height: 18px;
	border: 2px solid #649723;
	margin-top: 20px;
	
}
.radio-font {
	font-size: 18px;
	margin-right: 25px;
	color:#767676;
	margin-top: 20px;
}
js:

$(document).ready(function (){

	$("input[type='radio']").first().next().css('color','#649723');		//设置默认选项的文字为选中状态
	$(":radio").click(function (){
		$("input[type='radio']").ea
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值