«

checkbox批量选中,获取选中项的值的简单实例

时间:2024-3-2 09:03     作者:韩俊     分类: Html+Css


checkbox批量选中,获取选中项的值的简单实例

<!doctype html>
<html lang="en">
 <head>
 <meta charset="UTF-8">
 <title>Document</title>
 <script type="text/javascript" src="jquery.js"></script>
 </head>

 <body>
 <div id="table">
    <table id="personList" border="1">
    <tr>
    <th>ID</th>
    <th><input type="checkbox" name="allCheck" onclick="fun()"></input></th>
    <th>name</th>
    <th>age</th>
    <th>Country</th>
    </tr>
    <tr>
    <td>1</td>
    <th><input type="checkbox" name="checkme" id="a"></input></th>
    <td>asan</td>
    <td>32</td>
    <td>China</td>
    </tr>
    <tr>
    <td>2</td>
    <th><input type="checkbox" name="checkme" id="b3e"></input></th>
    <td>hon</td>
    <td>30</td>
    <td>JP</td>
    </tr>
    <tr>
    <td>3</td>
    <th><input type="checkbox" name="checkme" id="cdd"></input></th>
    <td>Jhone</td>
    <td>27</td>
    <td>USA</td>
    </tr>
    </table>

 </div>
 <input type="button" value="" onclick="s()" id="qw" name="aaa"/>

 <script>
    function fun(){
    var obj = document.getElementsByName("checkme");
    var arr = new Array();
    for(var i=0;i<obj.length;i++){
    obj[i].click();
    arr[i]=$(obj[i]).parent().siblings().first().text();
    alert(arr);
    }
}

function s(){
var obj = document.getElementsByName("checkme");
var arr = [];
for(var i=0;i<obj.length;i++){
if($(obj[i]).is(':checked')){
    var id = $(obj[i]).parent().siblings().first().text();
    var name = $(obj[i]).parent().siblings().eq(1).text();
    var age = $(obj[i]).parent().siblings().eq(2).text();
    var country = $(obj[i]).parent().siblings().eq(3).text();
    alert("id"+id+" ,name:"+name+" ,age:"+age+" ,country:"+country);
    //alert("$(obj[i]):"+$(obj[i])+" ,id:"+$(obj[i]).id+" ,name:"+$(obj[i]).name)
}
}
}

 </script>
 </body>
</html>

以上就是小编为大家带来的checkbox批量选中,获取选中项的值的简单实例全部内容了,希望大家多多支持毛票票~

标签: javascript html css

热门推荐