溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

HTML 之 Dom應用

發布時間:2020-07-13 00:15:33 來源:網絡 閱讀:239 作者:wx592bc92b285c7 欄目:web開發

理解

1、找到標簽
        獲取單個元素                document.getElementById(‘i1’)
        獲取多個元素(列表)     document.getElementsByTagName(“div”)
        獲取多個元素(列表)    document.getElementsByClassName(‘c1’)
        a.直接找
            document.getElementById             根據ID獲取一個標簽
            document.getElementsByName          根據name屬性獲取標簽集合
            document.getElementsByClassName 根據class屬性獲取標簽集合
            document.getElementsByTagName       根據標簽名獲取標簽集合         

2、操作標簽
        innerText
            獲取標簽中的文本內容
            標簽.innertText
            標簽賦值
            標簽.innertText = “”

        className
            tag.className =>  直接整體操作
            tag.classList.add(‘樣式名’)            添加指定樣式
            tag.classList.remove(‘樣式名’)     刪除指定樣式

代碼

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        .c1{
            background-color: #6e6568;
            position: fixed;
            top: 0;
            left:0;
            right: 0;
            bottom: 0;
            z-index: 9;
        }
        .c2{
            background-color: #e6e6e6;
            position: fixed;
            height: 300px;
            width: 300px;
            left:35%;
            top:23%;
            z-index: 10;
            opacity: 0.7;

        }
        .hide{
            display: none;
        }
    </style>
</head>
<body >

    <input type="button" onclick="ShowModule()" value="測試">

    <!--截擋層開始-->
    <div id="i1" class="c1 hide"></div>

    <!--字符輸入層-->
    <div id="i2" class="c2 hide">
        <div><span>用戶名:</span><input type="text" id="user"/></div>
        <div><span>密???碼:</span><input type="password" id="password"/></div>
        <div >
            <input type="button" value="確定"  onclick="ShowMsg()"/>
            <input type="button" value="取消"  onclick="addhide()"/>
        </div>
    </div>

    <!--js腳本-->
    <script>
        function ShowModule() {
            document.getElementById('i1').classList.remove('hide');
            document.getElementById('i2').classList.remove('hide');
        }
        function addhide() {
            document.getElementById('i1').classList.add('hide');
            document.getElementById('i2').classList.add('hide');
        }
        function ShowMsg() {
            var name = document.getElementById("user").value;
            alert(name);
        }

    </script>
</body>
</html>

展示

HTML 之 Dom應用

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

亚洲午夜精品一区二区_中文无码日韩欧免_久久香蕉精品视频_欧美主播一区二区三区美女