自定义属性-模态框的改进

1. 用this的话,跟顺序和索引就没有任何关系了,完全就是用属性绑定的。

如果要增加新的列的话,JS里面不需要做任何调整。

模态框程序如下:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        .hide{
            display:none;
        }
        .model{
            position:fixed;
            top:50%;
            left:50%;
            width:500px;
            height:400px;
            margin-left:-250px;
            margin-top:-250px;
            background-color:#eeeeee;
            z-index:10;
        }
        .shadow{
            position:fixed;
            top:0;
            left:0;
            right:0;
            bottom:0;
            opacity:0.6;
            background-color:black;
            z-index:9;
        }

    </style>
</head>
<body>
    <a onclick="addElement();">添加</a>
    <table border="1px">
        <tr>
            <td target="hostname">1.1.1.11</td>
            <td target="port">80</td>
            <td>
                <a class="edit">编辑</a> | <a>删除</a>
            </td>
        </tr>
                <tr>
            <td target="hostname">1.1.1.12</td>
            <td target="port">80</td>
            <td>
                <a class="edit">编辑</a> | <a>删除</a>
            </td>
        </tr>
                <tr>
            <td target="hostname">1.1.1.13</td>
            <td target="port">80</td>
            <td>
                <a class="edit">编辑</a> | <a>删除</a>
            </td>
        </tr>
    </table>
    <div  class="model hide">
        <div>
            <input name="hostname" type="text"/>
            <input name="port" type="text"/>
            <input type="text"/>
        </div>
        <div>
            <input type="button" value="取消" onclick="cancelModel();"/>
        </div>
    </div>
        <div class="shadow hide"></div>

    <script src="jquery-1.12.4.js"></script>
    <script>
        function addElement(){
            //$(‘.model‘).removeClass(‘hide‘);
            //$(‘.shadow‘).removeClass(‘hide‘);
            $(‘.model,.shadow‘).removeClass(‘hide‘);
        }
        function cancelModel(){
            $(‘.model,.shadow‘).addClass(‘hide‘);
            $(‘.model input[type="text"]‘).val("");
        }
        $(‘.edit‘).click(function(){
            $(‘.model,.shadow‘).removeClass(‘hide‘);
            //this 代指当前点击的标签
            var tds=$(this).parent().prevAll();
            tds.each(function(){
                //this,代指当前每个td;获取td的target属性值
                var n=$(this).attr(‘target‘);
                //获取td中的内容
                var text=$(this).text();
                var a1=‘.model input[name="‘;
                var a2=‘"]‘;
                var tmp=a1+n+a2;
                $(tmp).val(text);

            })

        });
    </script>

</body>
</html>
时间: 2024-07-29 04:49:28

自定义属性-模态框的改进的相关文章

关于手动关闭BootStrap模态框

在网上找手动关闭BootStrap模态框的解决方法,说是(需要引用bootstrap.js等): $("#myModal").modal('hide'); 但是我发现我的只能关闭 , 不能关闭下面那半透明层.找了下发现是出现这两行代码的缘故. <div class="modal-backdrop fade in"></div> <div class="modal-backdrop fade in"></d

模态框的理解 ,jQ: loading,进度条, 省级联动 ,富文本编辑器 表单验证 插件

模态框: 打开一个弹框 不关闭它就不能做框外的操作 必须关闭或弹出另外的弹框 加载延迟loading + 进度条只要有请求 就处理一下监控ajax 全局事件jquery: 开始     $('#box').ajaxStart() 多个ajax共享一个Start 发送 .ajaxSend() 成功 .ajaxSuccess() 完成 . ajaxComplete() 完成后有错误 .ajaxError() 停止 .ajaxStop()多个ajax共享一个Stop Nprogress:进度条引入 c

iframe中的模态框遮罩父窗口原理

关键点: css的position定位为fixed或absolute css的z-index, 最顶层的值最大如遮罩层为0那么弹出框最好是大于等于1的整数,总之记住弹出层要比遮罩的z-index值大就行 如果弹出模态框的使用场景没有嵌套在iframe或frame中掌握以上两点加上点css功底就可以写出漂亮的模态框了 特殊场景会涉及到跨域问题,可以在父页面和子页面分别设置<script type="text/javascript">document.domain="

bootstarp 模态框大小尺寸的控制

默认: <!-- 模态框(Modal) --> <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"> <div class="modal-dialog">

jQuery点击弹出层,弹出模态框,点击模态框消失

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 <!DOCTYPE html>

用vue实现模态框组件

基本上每个项目都需要用到模态框组件,由于在最近的项目中,alert组件和confirm是两套完全不一样的设计,所以我将他们分成了两个组件,本文主要讨论的是confirm组件的实现. 组件结构 <template> <div class="modal" v-show="show" transition="fade"> <div class="modal-dialog"> <div cla

关于bootstrap 在MVC里 模态框里加载iframe页面做编辑的时候

前台代码 <div class="modal fade" id="myModal" tabindex="-1" role="dialog"     aria-labelledby="myModalLabel" aria-hidden="true" >    <div class="modal-dialog" style="width:830

bootstrap模态框使用

需要引入的相关内容点击下载 <html><%@ page pageEncoding="UTF-8" contentType="text/html; charset=UTF-8" %><head> <title>BootStrap</title> <link rel="stylesheet" href="bootstrap.min.css"> <scr

Bootstrap 模态框实例插件

好久没有发过自己的代码的状态了,今天编写代码感觉有力不从心了.不过慢慢的找回了感觉,正好朋友问了我一个问题,就是如何实现模态框.其实就是引用bootstrap插件来实现. Bootstrap Modals(模态框)是使用定制的 Jquery 插件创建的.它可以用来创建模态窗口丰富用户体验,或者为用户添加实用功能.您可以在 Modals(模态框)中使用 Popover(弹出框)和 Tooltip(工具提示插件).页面中的模态框一般分为注册模态框.变更模态框.删除(信息提示)模态框三种基本模态框.