JQuery 模态对话框

JQuery 模态

<!-- jquery模态框可扩展版本 -->
<!DOCTYPE html>
<html lang="en">
<head>
    <script src="//cdn.bootcss.com/jquery/1.11.3/jquery.min.js"></script>
    <meta charset="UTF-8">
    <title>Document</title>
    <style>
        .hide{
            display:none;
        }
        .modal{
            position:fixed;
            left:50%;
            top:50%;
            width:500px;
            height:400px;
            margin-left:-200px;
            margin-top:-250px;
            z-index:10;
            background-color:white;
        }
        .shade{
            position:fixed;
            left:0;
            right:0;
            top:0;
            bottom:0;
            opacity:0.6;
            background-color:black;
            z-index:9;
        }
        p{
            text-align:center;
        }
    </style>
</head>
<body>
    <input type="button" value="添加">
    <div class="container">
        <table border="1">
            <tr>
                <td target="hostname">1.1.1.1</td>
                <td target="port">80</td>
                <td target="ip">192.168.1.101</td>
                <td><input type="button" value="编辑"> | <input type="button" value="删除"></td>
            </tr>
            <tr>
                <td target="hostname">1.1.1.2</td>
                <td target="port">81</td>
                <td target="ip">192.168.1.102</td>
                <td><input type="button" value="编辑"> | <input type="button" value="删除"></td>
            </tr>
            <tr>
                <td target="hostname">1.1.1.3</td>
                <td target="port">82</td>
                <td target="ip">192.168.1.103</td>
                <td><input type="button" value="编辑"> | <input type="button" value="删除"></td>
            </tr>
            <tr>
                <td target="hostname">1.1.1.4</td>
                <td target="port">83</td>
                <td target="ip">192.168.1.104</td>
                <td><input type="button" value="编辑"> | <input type="button" value="删除"></td>
            </tr>
        </table>
    </div>
    <div class="modal hide">
        <p>主机:<input name="hostname" type="text"></p>
        <p>端口:<input name="port" type="text"></p>
        <p>地址:<input name="ip" type="text"></p>
        <p><input type="button" value="取消"></p>
    </div>
    <div class="shade hide"></div>
    <script src="jquery-1.12.4.js"></script>
    <script>
        //添加按钮
        $('input[value="添加"]').click(function(){
            $('.hide').removeClass('hide');
        });
        //取消按钮
        $('input[value="取消"]').click(function(){
            $('input[type="text"]').val('');
            $('.modal,.shade').addClass('hide');
        });
        //编辑按钮
        $('input[value="编辑"]').click(function(){
            $('.hide').removeClass('hide');
            //获取点击前面标签
            var tds = $(this).parent().prevAll();
            tds.each(function(){
                //获取target值
                var tar_val = $(this).attr('target');
                //获取当前td的内容
                var con = $(this).text();
                //根据target寻找modal中的对应框,并写入内容
                $('.modal input[name="'+tar_val+'"]').val(con);
            });
        });
        //删除按钮
        $('input[value="删除"]').click(function(){
            $(this).parent().parent().remove();
        });
    </script>
</body>
</html>
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值