JavaScript/JQuery radioButton(单选按钮)练习20190409
2024-09-08 14:31:12
<!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.
最新文章
- phonegap创建的ios项目推送消息出现闪退现象
- 来抢你们IT狗的饭碗了
- JS常用的设计模式(7)—— 外观模式
- String.format 细节
- android4.0 禁止横竖屏切换使用 android:configChanges=";orientation|keyboardHidden";无效的解决方法
- 判断IMEI或MEID是否合法
- UESTC_冰雪奇缘 CDOJ 843
- JavaScript学习笔记——简单无缝循环滚动展示图片的实现
- 基于Proxy思想的Android插件框架
- PHP关联数组和哈希表(hash table) 未指定
- React - Stores
- java 关于性别的处理
- 精读《V8 引擎 Lazy Parsing》
- Beta 冲刺(7/7)
- Java序列化随记
- arcgis pro指数库
- 自制URL转换器
- <;9>;cc.Sprite组件
- mac install brew
- PHP标准库 SPL
热门文章
- vue 使用font-awesome 只需两步
- 基于active状态类名的web交互开发
- Table View Programming Guide for iOS---(七)---Managing Selections
- cocos2d-x 坐标系解惑
- UVa 1643 Angle and Squares (计算几何)
- Codeforces - 559B - Equivalent Strings - 分治
- HDU5145:5145 ( NPY and girls ) (莫队算法+排列组合+逆元)
- jzoj5980. 【WC2019模拟12.27】字符串游戏
- (六)SpringBoot整合Swagger2框架
- selenium中Xpath和CSS Selector的使用方法