84-85

模態編輯框

多層彈框設計

<!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="1">
        <tr>
            <td>1.1.1.11</td>
            <td>80</td>
            <td>
                <a class="edit">編輯</a> | <a>刪除</a>
            </td>
        </tr>
        <tr>
            <td>1.1.1.12</td>
            <td>80</td>
            <td>
                <a class="edit">編輯</a> | <a>刪除</a>
            </td>
        </tr>
        <tr>
            <td>1.1.1.13</td>
            <td>80</td>
            <td>
                <a class="edit">編輯</a> | <a>刪除</a>
            </td>
        </tr>
        <tr>
            <td>1.1.1.14</td>
            <td>80</td>
            <td>
                <a class="edit">編輯</a> | <a>刪除</a>
            </td>
        </tr>
    </table>

    <div class="model hide">
        <div>
            <input type="text">
            <input type="text">
            <input type="text">
        </div>
        <div>
            <input type="button" value="取消" onclick="cancleModel();">
        </div>
    </div>

    <div class="shadow hide"></div>

    <script src="jquery-1.12.4.js"></script>

    <script>
        function addElement() {
            $(".model,.shadow").removeClass("hide");    //當點擊添加時觸發函數,將model和shadow標籤中的hide標籤移出,就會顯彈出信息
        }
        function cancleModel() {
            $(".model,.shadow").addClass("hide");   //點取消,添加hide,隱藏彈出的信息
        }

    </script>

</body>
</html>

enter description here

內容操做:html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>

    <div id="i1">asdfadfasdf<a>asdfasd</a></div>

    <script src="jquery-1.12.4.js"></script>

</body>
</html>

enter description here

上圖:經過dom能夠獲取標籤的html和text內容jquery

enter description here

上圖:經過jQuery來獲取表現的html和text內容dom

enter description here

上圖:不添加參數是獲取值,添加參數就是賦值。讓html等於p標籤,且修改內容等於123123ide

enter description here

上圖:html能夠解析標籤,text不解析標籤,將<p></p>當作內容展示出來了。函數

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>

    <div id="i1">asdfadfasdf<a>asdfasd</a></div>

    <input id="i2" type="text">

    <script src="jquery-1.12.4.js"></script>

</body>
</html>

enter description here

上圖:input標籤經過.value獲取填寫的值this

enter description here

上圖:經過jQuery獲取input標籤的值設計

enter description here

上圖:jQuery設置值code

$().val() 不知能夠獲取和設置input標籤,只要dom.value能作的,jQuery的val都能操做。htm

<!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="1">
        <tr>
            <td>1.1.1.11</td>
            <td>80</td>
            <td>
                <a class="edit">編輯</a> | <a>刪除</a>
            </td>
        </tr>
        <tr>
            <td>1.1.1.12</td>
            <td>80</td>
            <td>
                <a class="edit">編輯</a> | <a>刪除</a>
            </td>
        </tr>
        <tr>
            <td>1.1.1.13</td>
            <td>80</td>
            <td>
                <a class="edit">編輯</a> | <a>刪除</a>
            </td>
        </tr>
        <tr>
            <td>1.1.1.14</td>
            <td>80</td>
            <td>
                <a class="edit">編輯</a> | <a>刪除</a>
            </td>
        </tr>
    </table>

    <div class="model hide">
        <div>
            <input name="hostname" type="text" value="">
            <input name="port" type="text" value="">

        </div>
        <div>
            <input type="button" value="取消" onclick="cancleModel();">
        </div>
    </div>

    <div class="shadow hide"></div>

    <script src="jquery-1.12.4.js"></script>

    <script>
        function addElement() {
            $(".model,.shadow").removeClass("hide");
        }
        function cancleModel() {
            $(".model,.shadow").addClass("hide");
        }

        $('.edit').click(function () {
            $(".model,.shadow").removeClass("hide");
            var tds = $(this).parent().prevAll();
            console.log(tds[0]);    //打印tds的第0個參數
            console.log(tds[1]);
        })

    </script>

</body>
</html>

enter description here

上圖:由於prevall,因此是從編輯開始向左查詢,編輯左邊下標0的內容是80,下標1的內容是1.1.1.11ip

<!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="1">
    <tr>
        <td>1.1.1.11</td>
        <td>80</td>
        <td>
            <a class="edit">編輯</a> | <a>刪除</a>
        </td>
    </tr>
    <tr>
        <td>1.1.1.12</td>
        <td>80</td>
        <td>
            <a class="edit">編輯</a> | <a>刪除</a>
        </td>
    </tr>
    <tr>
        <td>1.1.1.13</td>
        <td>80</td>
        <td>
            <a class="edit">編輯</a> | <a>刪除</a>
        </td>
    </tr>
    <tr>
        <td>1.1.1.14</td>
        <td>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">

    </div>
    <div>
        <input type="button" value="取消" onclick="cancleModel();">
    </div>
</div>

<div class="shadow hide"></div>

<script src="jquery-1.12.4.js"></script>

<script>
    function addElement() {
        $(".model,.shadow").removeClass("hide");
    }
    function cancleModel() {
        $(".model,.shadow").addClass("hide");
        $('.model input[type="text"]').val("");
    }

    $('.edit').click(function () {
        $(".model,.shadow").removeClass("hide");
        var tds = $(this).parent().prevAll();
        var port = $(tds[0]).text();
        var host = $(tds[1]).text();
        $('.model input[name="hostname"]').val(host);
        $('.model input[name="port"]').val(port);
    })

</script>

</body>
</html>

代碼說明:

$('.model input[type="text"]').val("");  當點擊編輯後,在去點擊添加,彈出的彈框中不是空數據,而是以前點擊的編輯數據,因此這裏在點取消後要將框中的內容清除。

var port = $(tds[0]).text();  根據下標獲取文本內容
var host = $(tds[1]).text();

$('.model input[name="hostname"]').val(host);   使用val()進行賦值
$('.model input[name="port"]').val(port);
本站公眾號
   歡迎關注本站公眾號,獲取更多信息