zoukankan      html  css  js  c++  java
  • jQuery 练习:取出数组字典的值, 静态对话框, clone方法应用

    jQuery 中文API文档 http://jquery.cuishifeng.cn/

    jQuery 取出数组字典的值

    <head>
        <meta charset="UTF-8">
        <title>Title</title>
        <script src="jquery-3.3.1.min.js"></script>
    </head>
    <body>
    <script>
        li = [1, 2, 3, 4, 5]
        $.each(li, function(i, x){
            console.log(i, x)                        // i 为索引,x为 value
        })
    
        dic={name:"yuan", sex:"male"}
        $.each(dic, function(i, x){
            console.log(i,x)                         // i 为 key,x为value
        })
    </script>
    </body>
    

    jQuery 实现全选,取消,反选功能

    <head>
        <meta charset="UTF-8">
        <title>Title</title>
        <script src="jquery-3.3.1.min.js"></script>
    </head>
    <body>
        <button onclick="selectall();">全选</button>
        <button onclick="cancel();">取消</button>
        <button onclick="reverse();">反选</button>
    
        <table border="1">
            <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>
            <tr>
                <td><input type="checkbox"></td>
                <td>444</td>
            </tr>
        </table>
    <script>
        function selectall(){
            $("table :checkbox").each(function(){
                $(this).prop("checked", true)
            })
        }
    
        function cancel(){
            $("table :checkbox").each(function(){
                $(this).prop("checked", false)
            })
        }
    
        function reverse(){
            $("table :checkbox").each(function(){
                if($(this).prop("checked")){
                    $(this).prop("checked", false);
                }else {
                    $(this).prop("checked", true);
                }
            })
        }
    </script>
    </body>
    

    jQuery 实现静态对话框

    <head>
        <meta charset="UTF-8">
        <title>Title</title>
        <style>
            .back{
                background-color: rebeccapurple;
                height: 2000px;
            }
    
            .shade{
                position: fixed;
                top: 0;
                bottom: 0;
                left: 0;
                right: 0;
                background-color: coral;
                opacity: 0.4;
            }
    
            .hide{
                display: none;
            }
    
            .models{
                position: fixed;
                top: 50%;
                left: 50%;
                margin-left: -100px;
                margin-top: -100px;
                height: 200px;
                 200px;
                background-color: gold;
            }
        </style>
        <script src="jquery-3.3.1.min.js"></script>
    </head>
    <body>
    <div class="back">
        <input id="ID1" type="button" value="click" onclick="action1(this)">
    </div>
    
    <div class="shade hide"></div>
    <div class="models hide">
        <input id="ID2" type="button" value="cancel" onclick="action2(this)">
    </div>
    
    <script>
        function action1(self){
            $(self).parent().siblings().removeClass("hide");
        }
    
        function action2(self){
            $(self).parent().parent().children(".shade, .models").addClass("hide");
        }
    </script>
    </body>
    

    jQuery clone方法应用

    <head>
        <meta charset="UTF-8">
        <title>Title</title>
        <script src="jquery-3.3.1.min.js"></script>
    </head>
    <body>
    
    <div id="outer">
        <div class="item">
            <input type="button" value="+" onclick="fun1(this)">
            <input type="text">
        </div>
    </div>
    
    <script>
        function fun1(self){
            var Clone=$(self).parent().clone();
            Clone.children(":button").val("-").attr("onclick", "func2(this)");
            $("#outer").append(Clone);
        }
    
        function func2(self){
            $(self).parent().remove()
        }
    </script>
    </body>
    
  • 相关阅读:
    ASP.NET页面生命周期
    C#之virtual override new解析
    js之闭包、this
    C#使用定时任务框架Windows.TaskSchedule.exe安装控制台应用程序创建的Windows服务
    C# 利用 Windows服务模板 创建、安装与卸载Windows服务
    SQL代码生成器
    C#之JSON序列化与反序列化
    Vue源码学习1——Vue构造函数
    angular编写表单验证
    使用canvas编写时间轴插件
  • 原文地址:https://www.cnblogs.com/klvchen/p/10400989.html
Copyright © 2011-2022 走看看