最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

jQuery實現(xiàn)全選反選操作案例

 更新時間:2021年08月10日 14:02:11   作者:來干了這碗代碼  
這篇文章主要為大家詳細介紹了jQuery實現(xiàn)全選操作案例,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下

本文實例為大家分享了jQuery實現(xiàn)全選反選操作的具體代碼,供大家參考,具體內(nèi)容如下

全選+反選

可根據(jù)控制臺結(jié)合查看結(jié)果

<!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>過濾選擇器</title>
    <script src="jquery-3.2.1.min.js"></script>
</head>

<body>

    <table border="1">
        <tr>
            <td><input type="checkbox" value="1"></td>
            <td>劍圣</td>
            <td>450</td>
        </tr>
        <tr>
            <td><input type="checkbox" value="2"></td>
            <td>劍豪</td>
            <td>6300</td>
        </tr>
        <tr>
            <td><input type="checkbox" value="3"></td>
            <td>劍姬</td>
            <td>6300</td>
        </tr>
        <tr>
            <td><input type="checkbox" value="4"></td>
            <td>劍魔</td>
            <td>6300</td>
        </tr>
    </table>
 
    <input type="button" value="點擊選擇使用第一個" id="firstBtn">
    <input type="button" value="點擊選擇使用最后一個" id="lastBtn">
    <input type="button" value="全選適用于批量刪除" id="allBtn">
    <input type="button" value="查看已選中的" id="checkBtn">
    <input type="button" value="查看未選中的" id="nocheckBtn">
    <input type="button" value="反選" id="overBtn">
    <input type="button" value="反選的升級版" id="overBtn1">

<script>

        $(function() {
            //jQuery 使用過濾選擇器 達到 奇偶數(shù)變色
            $("table tr:even").css('background-color','pink');
            $("table tr:odd").css('background-color','blue');
            // 
            
            // 拿去第一個
            $("#firstBtn").click(function() {
                var first = $("table tr:first").html();
                console.log(first);  
            })

             // 拿取最后一個
             $("#lastBtn").click(function() {
                var last = $("table tr:last").text();
                console.log(last);  
            })
            // 全選 ---- 用來批量刪除
            $("#allBtn").click(function() { 
                // 思路找出所有 checkbox的 td 進行遍歷 選中即可 
                $.each($("table tr td>input"), function(index, value) {
                  //  console.log(index);   
                  //  console.log(value);
                    console.log($(this).val()); // 遍歷取值
                    $(this).prop('checked',true); // 全選
                })

            }) 
            // 點擊查看已經(jīng)選中的
            $("#checkBtn").click(function() { 
                // 使用過濾選擇器 可以選中 :
                $("table tr td>input:checked")
                $.each($("table tr td>input:checked"), function(index, value) {
                    
                    console.log($(this).val()); // 遍歷取值
                    
                })
            
            }) 
            // 點擊查看未選中的
            $("#nocheckBtn").click(function() { 
                console.log($("table tr td>input:not(:checked)"))
            })
            // 反選
            $("#overBtn").click(function() { 
                $.each($("table tr td>input"), function(index, value) {
                    var istrue =$(this).prop("checked");
                    //console.log(value.checked = !value.checked); // 遍歷取值
                   if(istrue){
                        $(this).prop("checked",false);
                   } else{
                    $(this).prop("checked",true);
                   }
                })   
            })     
            // 升級版的全/反選
            $("#overBtn1").click(function() { 
                $.each($("table tr td>input"), function(index, value){
                $(this).prop("checked",!$(this).prop("checked"))
                })
            })
    })  
</script>

</body>
</html>

以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。

相關文章

最新評論

梁山县| 南木林县| 赣州市| 拉孜县| 新民市| 万盛区| 乌鲁木齐县| 皋兰县| 安丘市| 吐鲁番市| 芦溪县| 蓬安县| 中宁县| 华亭县| 葫芦岛市| 南昌县| 大名县| 武邑县| 澄江县| 贵州省| 咸丰县| 巢湖市| 林芝县| 沭阳县| 若尔盖县| 蓬溪县| 九寨沟县| 松原市| 恩平市| 镇原县| 恩平市| 九江县| 灌南县| 桂平市| 兴海县| 牙克石市| 安仁县| 石渠县| 秦安县| 报价| 长汀县|