<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<script type="text/javascript" src="scripts/jquery-3.3.1.js"></script>
</head>
<body> <div id="checkBoxDiv1">
测试单选框
<input type="radio" name="checkBox1" class="checkBox1"><input type="radio" name="checkBox1" class="checkBox1" checked="checked">
</div> <script type="text/javascript"> $(".checkBox1").on("click", function(){
var i = 0;
var parentEle = $(this).parent();
var index = $(this).index();
$(".checkBox1").each(function(){
var currentEle = parentEle.children(".checkBox1:eq(" + i + ")");
if(i == index){
currentEle.attr("checked", true);
}else{
currentEle.attr("checked", false);
}
i++;
});
i = 0;
$(".checkBox1").each(function(){
var currentEle = parentEle.children(".checkBox1:eq(" + i + ")");
alert(currentEle.attr("checked"));
i++;
});
}); </script> </body>
</html>

这个是用来满足特殊需求的勾选一个单选按钮checked设置为true,其他的同name的单选框checked都设置为false.

最新文章

  1. phonegap创建的ios项目推送消息出现闪退现象
  2. 来抢你们IT狗的饭碗了
  3. JS常用的设计模式(7)—— 外观模式
  4. String.format 细节
  5. android4.0 禁止横竖屏切换使用 android:configChanges=&quot;orientation|keyboardHidden&quot;无效的解决方法
  6. 判断IMEI或MEID是否合法
  7. UESTC_冰雪奇缘 CDOJ 843
  8. JavaScript学习笔记——简单无缝循环滚动展示图片的实现
  9. 基于Proxy思想的Android插件框架
  10. PHP关联数组和哈希表(hash table) 未指定
  11. React - Stores
  12. java 关于性别的处理
  13. 精读《V8 引擎 Lazy Parsing》
  14. Beta 冲刺(7/7)
  15. Java序列化随记
  16. arcgis pro指数库
  17. 自制URL转换器
  18. &lt;9&gt;cc.Sprite组件
  19. mac install brew
  20. PHP标准库 SPL

热门文章

  1. vue 使用font-awesome 只需两步
  2. 基于active状态类名的web交互开发
  3. Table View Programming Guide for iOS---(七)---Managing Selections
  4. cocos2d-x 坐标系解惑
  5. UVa 1643 Angle and Squares (计算几何)
  6. Codeforces - 559B - Equivalent Strings - 分治
  7. HDU5145:5145 ( NPY and girls ) (莫队算法+排列组合+逆元)
  8. jzoj5980. 【WC2019模拟12.27】字符串游戏
  9. (六)SpringBoot整合Swagger2框架
  10. selenium中Xpath和CSS Selector的使用方法