网络编程 发布日期:2025/11/10 浏览次数:1
一、需要实现的效果
这里使用jQuery来实现。需要实现的效果如下:当下拉条改变时,单选框选中的值随之变化。
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>动态设置单选框的选中</title>
<!--
作者:Harrison
时间:2018-12-05
描述:当下拉条改变时,动态的设置单选框的值
-->
</head>
<body>
<select id="sexSelect" style="width: 10%;">
<option value="1">男</option>
<option value="2">女</option>
</select>
男:<input type="radio" value="1" name="sex" id="sexRadio1" checked/>
女:<input type="radio" value="2" name="sex" id="sexRadio2"/>
</body>
<script type="text/javascript" src="/UploadFiles/2021-04-02/jquery-1.7.2.min.js">
二、注意
"#sexRadio1").prop("checked",true);
错误:$("#sexRadio1").prop("checked","true");
总结
以上所述是小编给大家介绍的使用jQuery动态设置单选框的选中效果,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对网站的支持!