首页 > Web开发 > 详细

JQuery

时间:2018-07-09 17:04:11      阅读:162      评论:0      收藏:0      [点我收藏+]

JQuery

 

 

实例:

多选/复选

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="JQuery-1.12.4.js"></script>
</head>
<body>
    <input type="button" value="all" onclick="chooseAll()">
    <input type="button" value="noAll" onclick="chooseNo()">
    <input type="button" value="reverseAll" onclick="reverseAll()">

    <table border="1">
        <thead>
            <tr>
                <th>checked</th>
                <th>ip</th>
                <th>port</th>
            </tr>
        </thead>
        <tbody>
            <tr>
                <td><input type="checkbox"> </td>
                <td>2.2.2.2</td>
                <td>32</td>
            </tr>
            <tr>
                <td><input type="checkbox"> </td>
                <td>2.3.3.3</td>
                <td>33</td>
            </tr>
            <tr>
                <td><input type="checkbox"> </td>
                <td>2.4.4.4</td>
                <td>34</td>
            </tr>
        </tbody>
    </table>

</body>
</html>

<script>
    function chooseAll(){
        $(‘:checkbox‘).prop(‘checked‘, true);
    }

    function chooseNo(){
        $(‘:checkbox‘).prop(‘checked‘, false);
    }

    function reverseAll(){
        $(‘:checkbox‘).each(function(k){
            //this:当前循环的每一个元素
            //k key-index,
            console.log(k, this)
            if(this.checked){
                this.checked = false
            }
            else{
                this.checked = true
            }
        })
    }
</script>

 

JQuery

原文:https://www.cnblogs.com/hinimix/p/9284601.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!