<body>
<form>
<input type="radio" name='radio' value="1" onclick='check(this)'>单选一
<input type="radio" name='radio' value="2" onclick='check(this)'>单选二
</form>
<script language="javascript">
var tempradio= null;
function check(checkedRadio)
{
if(tempradio== checkedRadio){
//tempradio.checked=false; 这句跟下面一句都可以
checkedRadio.checked=false;
tempradio=null;
}
else{
tempradio= checkedRadio;
}
}
</script>
<!-- 第一点击时传入单选对象,执行else,把这个对象赋给tempradio,第二次点击时checkedRadio这个对象就等于tempradio这个对象,执行if tempradio.checked=false; 又把tempradio 赋值为null, 然后不停的循环-->
</body>
在一个form中的单选按钮,同一个name都会只选中一个。
(adsbygoogle = window.adsbygoogle || []).push({});
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有