jquery

三元运算:

var a = if 条件?真值:假值

 

 

全选,反选

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src='jquery-3.4.0.js'></script>
</head>
<body>
    <table border="1px" width="200px">
        <thead>
        <tr id="i1">
            <th><input type="button" value="全选" οnclick="f1()"/></th>
            <th><input type="button" value="取消" οnclick="f2()"/></th>
            <th><input type="button" value="反选" οnclick="f3()"/></th>
        </tr>
        </thead>
        <tbody >
        <tr >
            <td><input type="checkbox" /></td>
            <td>id</td>
            <td>port</td>
        </tr>
        <tr>
            <td><input type="checkbox" /></td>
            <td>123</td>
            <td>456</td>
        </tr>
        <tr>
            <td><input type="checkbox" /></td>
            <td>123</td>
            <td>456</td>
        </tr>
        <tr>
            <td><input type="checkbox" /></td>
            <td>123</td>
            <td>456</td>
        </tr>
        </tbody>
    </table>
    <script>
        console.log($(':button:first'));
        function f1() {
            $('tbody :checkbox').prop('checked',true)
        }
        function f2 () {
            $('tbody :checkbox').prop('checked',false)
        }
        function f3(){
            $(':checkbox').each(function () {
                if (this.checked){
                    this.checked = false
                }
                else{
                    this.checked = true
                }
            })}
    </script>

</body>
</html>
View Code

 

左侧菜单

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        .c1{
            background-color: blue;
            width: 200px;
        }
        .hide{
            display: none;
        }
    </style>
    <script src="jquery-3.4.0.js"></script>
</head>
<body>
    <div class="c1" >
        菜单1
    </div>
    <div class="hide">
        <div>内容一</div>
        <div>内容一</div>
        <div>内容一</div>
    </div>
    <div class="c1" >
        菜单2
    </div>
    <div class="hide">
        <div>内容一</div>
        <div>内容一</div>
        <div>内容一</div>
    </div>
    <div class="c1" >
        菜单3
    </div>
    <div class="hide">
        <div>内容一</div>
        <div>内容一</div>
        <div>内容一</div>
    </div>
<script>
    console.log($('.c1'));
    $('.c1').click(function () {
        $('.c1').next().addClass('hide');
        $(this).next().removeClass('hide')
    })
</script>
</body>
</html>
View Code

 

 

 

模态对话框:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        .page{}
        .edit{}
        .hide{
            display: none;
        }
        .shadow{
            position: fixed;
            right: 0px;
            left: 0px;
            top: 0px;
            bottom: 0px;
            background-color: grey;
            opacity: 0.5;
            z-index: 5;
            }
        .windows{
            position: fixed;
            width: 500px;
            height: 300px;
            left: 50%;
            top: 50%;
            margin-top: -150px;
            margin-left: -250px;
            background-color: white;
            z-index: 6;
        }
    </style>
</head>
<body>
    <div class="shadow hide">

    </div>

    <div class="windows hide">
        <p><input type="text"></p>
        <p><input type="password"></p>
        <p><input type="button" value="ok"></p>
        <p><input type="button" value="cancel"></p>
    </div>

    <div class="page">
    <input type="button" value="add" >
    <table border="1px" >
        <thead>
        <tr>
            <th>No.</th>
            <th>ip</th>
            <th>port</th>
            <th>edit</th>
        </tr>
        </thead>
        <tbody>
        <tr >
            <td>1</td>
            <td>192.163.0.0</td>
            <td>8888</td>
            <td class="edit">edit</td>
        </tr>
        <tr>
            <td>2</td>
            <td>192.163.0.1</td>
            <td>8000</td>
            <td class="edit">edit</td>
        </tr>
        <tr>
            <td>2</td>
            <td>192.163.0.2</td>
            <td>8008</td>
            <td class="edit">edit</td>
        </tr>
        </tbody>
    </table>
</div>

    <script src="jquery-3.4.0.js"></script>
    <script>
        $('.page :button').click(function () {
            $('.shadow, .windows').removeClass('hide')
        });
        $('.edit').click(function () {
            $('.shadow, .windows').removeClass('hide');
            var idd = $(this).prev().prev().text()
            $('.windows :text').val(idd)
            var idd = $(this).prev().text()
            $('.windows :password').val(idd)
        })
    </script>
</body>
</html>
View Code

 

转载于:https://www.cnblogs.com/mushuiyishan/p/10782274.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值