zoukankan      html  css  js  c++  java
  • jquery循环方法

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Title</title>
    </head>
    <body>
    
        <p>p1</p>
        <p>p2</p>
        <p>p3</p>
        <script src="jquery-3.3.1.js"></script>
        <script>
            attr=[11,22,33]
            // for (var i=0;i<attr.length;i++) {
            //     $('p').eq(i).html(attr[i]);
            // }; // js可以混用jquery
    
            // jquery循环方式一
            $.each(attr,function (x,y) {
                console.log(x); // 0 1 2
                console.log(y); // 11 22 33
            });
            // jquery循环方式二
            $('p').each(function () {
                console.log($(this));
                $(this).html('p');
            }); // 对三个p标签进行循环,$this表示的是每个p标签,对标签的循环用的更多一些
        </script>
    
        <!--正反选案例练习-->
        <button onclick="selectAll()">全选</button>
        <button onclick="reverse()">反选</button>
        <button onclick="cancel1()">取消</button>
        <table border="1px">
            <tr>
                <td><input type="checkbox"></td>
                <td>111</td>
            </tr>
            <tr>
                <td><input type="checkbox"></td>
                <td>222</td>
            </tr>
            <tr>
                <td><input type="checkbox"></td>
                <td>333</td>
            </tr>
        </table>
        <script>
            function selectAll() {
                $(':checkbox').each(function () {
                    $(this).prop('checked',true);
                })
            };
            function cancel1() {
                $(':checkbox').each(function () {
                    $(this).prop('checked',false);
                })
            };
            function reverse() {
                $(':checkbox').each(function () {
                    if ($(this).prop('checked')) {
                        $(this).prop('checked',false)
                    }else{
                        $(this).prop('checked',true)
                    }
                })
            };
        </script>
    
    </body>
    </html>
    while True: print('studying...')
  • 相关阅读:
    [Leetcode]480. Sliding Window Median
    C++的一些小的知识点
    extern关键字
    c++的默认构造函数 VS 深拷贝(值拷贝) 与 浅拷贝(位拷贝)
    inline-内联函数的优点以及与宏定义的区别
    char类型输出地址
    c++ 对象的内存布局
    Shell 去掉文本中的空格
    牛客网-网易编程题 双端队列找规律
    计算机网络概观
  • 原文地址:https://www.cnblogs.com/xuewei95/p/15041847.html
Copyright © 2011-2022 走看看