首页 > 代码库 > checked多选,取消,反选
checked多选,取消,反选
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> </head> <body> <div> <input type="button" value="全选" ondblclick="ChooseAll();"> <input type="button" value="取消" ondblclick="CancelAll();"> <input type="button" value="反选" ondblclick="TrunAll();"> </div> <div> <table> <thead> <tr> <th>序号</th> <th>用户</th> <th>年龄</th> </tr> </thead> <tbody id="c1"> <tr > <td ><input class="i1" type="checkbox"/></td> <td>alex</td> <td>18</td> </tr> <tr> <td ><input class="i1" type="checkbox"/></td> <td>alex</td> <td>18</td> </tr> <tr > <td ><input class="i1" type="checkbox"/></td> <td>alex</td> <td>18</td> </tr> </tbody> </table> </div> <script> function ChooseAll() { var td= document.getElementById(‘c1‘); var doc = td.getElementsByClassName(‘i1‘); for(var i=0;i<doc.length;i++){ var current = doc[i]; current.checked = true; } } function CancelAll() { var td= document.getElementById(‘c1‘); var doc = td.getElementsByClassName(‘i1‘); for(var i=0;i<doc.length;i++) { var current = doc[i]; current.checked = false; } } function TrunAll() { var td= document.getElementById(‘c1‘); var doc = td.getElementsByClassName(‘i1‘); for(var i=0;i<doc.length;i++) { var current = doc[i]; if (current.checked){ current.checked = false; }else { current.checked = true; } } } </script> </body> </html>
checked多选,取消,反选
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。