源码如下:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> </head> <body> <a onclick="delInfo()">批量刪除</a> <table t> <tr> <th><input type="checkbox" onclick="onchoose()"/>全选/全不选</th> <td>测试列</td> </tr> <tr> <td> <input type="checkbox" class="choose" value="1"/> </td> <td>有数据</td> </tr> <tr> <td> <input type="checkbox" class="choose" value="2"/> </td> <td>有数据</td> </tr> <tr> <td> <input type="checkbox" class="choose" value="3"/> </td> <td>有数据</td> </tr> <tr> <td> <input type="checkbox" class="choose" value="4"/> </td> <td>有数据</td> </tr> </table> <script> var a=0; function onchoose(o){ a=a==0?1:0; var arr=document.getElementsByClassName("choose"); for (var i = 0; i < arr.length;i++) { arr[i].checked=a==0?false:true; } } function delInfo(){ var ids=""; var arr=document.getElementsByClassName("choose"); for (var i = 0; i < arr.length;i++) { if(arr[i].checked==true){ ids+=arr[i].value+"," } } console.log(ids) } </script> </body> </html>