html簡單table、彈層實(shí)例

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        /*<!--默認(rèn)彈層不顯示-->*/
        .hide{
            display: none;
        }
        .s1{
            position: fixed;
            top: 0;
            right: 0;
            bottom: 0;
            left: 0;
            background-color: black;
            opacity: 0.6;
            z-index: 1;
        }
        .s2{
            z-index: 2;
            position: fixed;
            width: 200px;
            height: 200px;
            left: 50%;
            top: 50%;
            margin-left: -100px;
            margin-top: -100px;
            background-color: white;
        }

    </style>
</head>
<body>

<div>
    <input type="button" value="添加" onclick="showModel();">
    <input type="button" value="全選" onclick="chooseall();">
    <input type="button" value="取消" onclick="cancelall();">
    <input type="button" value="反選" onclick="reversall();"><br>
    <table>
        <thead>
            <tr>選擇&nbsp;&nbsp;</tr>
            <tr>主機(jī)名&nbsp;&nbsp;</tr>
            <tr>端口</tr>
        </thead>
        <tbody id="td">
            <tr>
                <td><input type="checkbox"></td>
                <td>1.1.1.1</td>
                <td>9999</td>
            </tr>
            <tr>
                <td><input type="checkbox"></td>
                <td>1.1.1.2</td>
                <td>9989</td>
            </tr>
            <tr>
                <td><input type="checkbox"></td>
                <td>1.1.1.3</td>
                <td>9997</td>
            </tr>
        </tbody>
    </table>
</div>

<!--第一個遮罩層-->
<div class="s1 hide" id="r1"></div>

<!--第二個輸入框彈層-->
<div class="s2 hide" id="r2">
    <input type="text"><br>
    <input type="text"><br>
    <input type="button" value="取消" onclick="hideModel();">
    <input type="button" value="添加" >
</div>
<script>
    function showModel() {
        document.getElementById('r1').classList.remove('hide')
        document.getElementById('r2').classList.remove('hide')
    }
    function hideModel() {
        document.getElementById('r1').classList.add('hide')
        document.getElementById('r2').classList.add('hide')
    }
    function chooseall() {
        var tbody = document.getElementById('td');
        var tr_list = tbody.children;
        for (var i = 0;i<tr_list.length;i++){
            var current_tr = tr_list[i];
            var checkbox = current_tr.children[0].children[0];
            checkbox.checked = true;
        }
    }
    function cancelall() {
        var tbody = document.getElementById('td');
        var tr_list = tbody.children;
        for (var i = 0;i<tr_list.length;i++){
            var current_tr = tr_list[i];
            var checkbox = current_tr.children[0].children[0];
            checkbox.checked = false;
        }
    }
    function reversall() {
        var tbody = document.getElementById('td');
        var tr_list = tbody.children;
        for (var i = 0;i<tr_list.length;i++){
            var current_tr = tr_list[i];
            var checkbox = current_tr.children[0].children[0];
            if (checkbox.checked == true){
                checkbox.checked = false;
            }else {
                checkbox.checked = true;
            }
        }
    }
</script>
</body>
</html>
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容