温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

jQuery 之 多选反选取消实例

发布时间:2020-08-10 22:44:49 来源:网络 阅读:221 作者:wx592bc92b285c7 栏目:web开发

代码:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="jquery3.js"></script>
</head>
<body>
    <table border="1">
        <thead>
        <tr>
            <th >选择</th>
            <th >IP</th>
            <th >端口</th>
        </tr>
        </thead>
        <tbody>
        <tr>
            <td><input type="checkbox"></td>
            <td>1.1.1.1</td>
            <td>80</td>
        </tr>
        <tr>
            <td><input type="checkbox"></td>
            <td>2.2.2.2</td>
            <td>80</td>
        </tr>
        <tr>
            <td><input type="checkbox"></td>
            <td>3.3.3.3</td>
            <td>80</td>
        </tr>
        </tbody>
    </table>
    <input type="button" value="全选" onclick="checkAll()">
    <input type="button" value="反选" onclick="reverseAll()">
    <input type="button" value="取消" onclick="cancleAll()">
    <script>
        function checkAll() {
//            把checkbox的checked值设置为true
            $(':checkbox').prop('checked',true)
//            $(':checkbox').prop('checked')为获取值
        }
        function cancleAll() {
//            把checkbox的checked值设置为false
            $(':checkbox').prop('checked',false)
//            $(':checkbox').prop('checked')为获取值
        }
        function reverseAll() {
            $(':checkbox').each(function (k) {
                // k当前索引
                // this,DOM元素,当前循环的元素$(this)
                if(this.checked)
                {
                    this.checked = false;
                }
                else{
                    this.checked = true;
                }
            })
        }
    </script>

</body>
</html>

展示:

jQuery 之 多选反选取消实例

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI