早就想写点博客了 一直懒着动  最近发现一些写过的东西都不记得了,下决心把自己平时遇到的问题、得到的经验记录下来,希望能大家一点帮助

  这是之前写的一个模态框 要求单选 但是 要求radio的默认样式 太难看了 就想用checkbox + js 自己把它改成单选框 如下:

  html代码:

<div class="list-item">
<input type="checkbox" id="1" value="">
<label for="1">Dance of the Reed Pipes</label>
</div>
<div class="list-item">
<input type="checkbox" id="2" value="">
<label for="2">Dance of the Reed Pies</label>
</div>
<div class="list-item">
<input type="checkbox" id="3" value="">
<label for="3">Dance of the Reed Pipes</label>
</div>
<div class="list-item">
<input type="checkbox" id="4" value="">
<label for="4">Dance of the Reed Pipes</label>
</div>
<div class="list-item">
<input type="checkbox" id="5" value="">
<label for="5">Dance of the Reed Pipes</label>
</div>

  js代码:

$(".list-item").click(function(){
$(".list-item").find("input[type='checkbox']").prop("checked", false);//每次点击前,将所有checkbox置为 未选中
var cobj = $(this).find("input[type='checkbox']");//当前点击的checkbox
cobj.prop("checked", true);//将当前点击的checkbox置为选中状态
//over
})

  代码并不复杂 挺简单的 ,如果想获取点击的id,只要再加一句

var itemId = cobj.attr("id");

  这样就可以了

最新文章

  1. iOS Architectures 浅谈
  2. JAVA中去掉空格经典整理
  3. 第六周——分析Linux内核创建一个新进程的过程
  4. bzoj1104: [POI2007]洪水pow
  5. mysql主主复制(双主复制)配置步骤
  6. js系列(9)js的运用(一)
  7. 分分钟知道tiles框架是干嘛的
  8. power desinger 学习笔记&lt;二&gt;
  9. Bitmap recycle()
  10. 做.net的早晚会用到,并且网上还没有这方面的正确资料或几乎很少
  11. vue 父子之间通信及非父子之间通信
  12. Python 学习笔记6 变量-元组
  13. docker 系列 - Java程序制作Docker Image推荐方案(转载)
  14. 使用WinIo32绕过密码控件实现自动登录
  15. C++ 是 编程界 的 背锅侠
  16. Caused by: org.xml.sax.SAXParseException; lineNumber: 1
  17. linux 源码安装 mono
  18. Android wifi powersave
  19. 《剑指offer》第三十七题(序列化二叉树)
  20. n = 3 , while n , continue

热门文章

  1. 执行查询&ldquo;BACKUP LOG [XXX] TO DISK = N'F:\\BackData\\事务日至备份\\...&rdquo;失败,错误如下:&ldquo;无法执行 BACKUP LOG,因为当前没有数据库备份。 BACKUP LOG 正在异常终止。
  2. 通过pyenv和virtualenv创建多版本Python虚拟环境
  3. EditTable-V1.0--续集
  4. css多重边框
  5. sql server存储过程实现批量删除
  6. rtx web 分级管理系统 二次开发
  7. node 和git 在linux(centos) 上的安装
  8. H5 调用手机摄像机、相册功能
  9. Keepalived实战(3)
  10. 一步一步创建ASP.NET MVC5程序[Repository+Autofac+Automapper+SqlSugar](一)