小男孩‘自慰网亚洲一区二区,亚洲一级在线播放毛片,亚洲中文字幕av每天更新,黄aⅴ永久免费无码,91成人午夜在线精品,色网站免费在线观看,亚洲欧洲wwwww在线观看

分享

JavaScript連載37-切換選項(xiàng)卡樣式以及搭建一個(gè)評(píng)論系統(tǒng)

 Coder編程 2021-09-12

一、選項(xiàng)卡

  • 使用函數(shù)來(lái)動(dòng)態(tài)的顯示標(biāo)簽的樣式,也可以使用html自帶的動(dòng)畫效果來(lái)實(shí)現(xiàn)下面的操作
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>D37_1_OptionCard</title>
    <style>
        *{
            margin:0;
            padding:0;
        }
        a{
            text-decoration:none;
            color:#000000;
        }
        #tab{
            width:498px;
            height:120px;
            border:1px solid #ccc;
            margin:100px auto;
        }
        #tab_header{
            background-color: #e8e8e8;
            padding:0 1px;
            border-bottom:1px solid #cccccc;
            cursor:pointer;
        }
        #tab_header ul li.selected{
            background-color:#fff;
            border-bottom:none;

            /*左右線條*/
            border-left:1px solid #ccc;
            border-right:1px solid #ccc;

            padding:0;
        }
        #tab_header ul li:nth-child(1){
            border-left:none;
        }

    </style>
</head>
<body>
    <div id="tab">
        <!--頭部-->
        <div id="tab_header">
            <ul>
                <li class="selected">公告</li>
                <li>規(guī)則</li>
                <li>論壇</li>
                <li>安全</li>
                <li>公益</li>
            </ul>
        </div>
        <div id="tab_content">
            <ul>
                <li class="dom">我是第一個(gè)顯示的</li>
                <li class="dom">我是第二個(gè)顯示的</li>
                <li class="dom">我是第三個(gè)顯示的</li>
                <li class="dom">我是第四個(gè)顯示的</li>
                <li class="dom">我是第五個(gè)顯示的</li>
            </ul>
        </div>
    </div>
    <script>
        window.onload=function (ev) {
            //1.獲取標(biāo)簽
            var allLists = $("tab_header").getElementsByTagName("li");
            var allDom = $("tab_content").getElementsByClassName("dom");
            //2.遍歷監(jiān)聽
            for(var i=0;i<allLists.length;i++){
                var li= allLists[i];
                (function (i) {
                    li.onmouserover = function (ev2) {
                        //這里復(fù)習(xí)了鼠標(biāo)懸浮在某一塊
                        //清除同級(jí)別的選中樣式類
                        for(var j=0;j<allLists.length;j++){
                            allLists[j].className='';
                            allDom[j].style.display = "none";
                        }
                        //設(shè)置當(dāng)前的li標(biāo)簽選中的樣式
                        li.className = "selected";//一定注意使用className
                        allDom[i].style.display = "block";
                    }
                })(i)
            }
        }
        function $(id) {
            return typeof id == 'string' ? document.getElementById(id) : null;
        }
    </script>
</body>
</html>
37.1
37.1

二、構(gòu)建評(píng)論區(qū)

  • 我們先構(gòu)建一個(gè)評(píng)論區(qū)的框架,當(dāng)我們點(diǎn)擊發(fā)表的時(shí)候,就會(huì)在ul標(biāo)簽中新增一個(gè)li標(biāo)簽,然后li標(biāo)簽里面的內(nèi)容就是評(píng)論內(nèi)容,至于具體實(shí)現(xiàn)邏輯我們下次再寫。
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>D37_2_Review</title>
    <style>
        *{
            margin:0;
            padding:0;
            list-style:none;
        }
        #box{
            width:800px;
            border:1px solid #ccc;
            margin:100px auto;
            padding:20px;
        }
        #my_textarea{
            width:80%;
            height:120px;
        }
        .box-top{
            margin-bottom:20px;
        }
        #ul{
            margin:0 80px;
        }
        #ul li{
            border-bottom:1px dashed #ccc;
            color:red;
            line-height:44px;
        }
        #ul li a{
            float:right;
        }
    
</style>
</head>
<body>
    <div id="box">
        <div class="box-top">
            <label>發(fā)表評(píng)論:</label>
            <textarea id="my_textarea" cols="60" rows="10"></textarea>
            <button id="btn">發(fā)表</button>
        </div>
        <ul id="ul">
            <!--我們點(diǎn)擊發(fā)表按鈕,這里面就會(huì)多一個(gè)li標(biāo)簽,就是用來(lái)放評(píng)論的-->

        </ul>
    </div>
</body>
</html>
37.2
37.2

三、源碼:

  • D37_1_OptionCard.html
  • D37_2_Review.html
  • 地址:https://github.com/ruigege66/JavaScript/blob/master/D37_1_OptionCard.html
  • https://github.com/ruigege66/JavaScript/blob/master/D37_2_Review.html
  • 博客園:https://www.cnblogs.com/ruigege0000/
  • CSDN:https://blog.csdn.net/weixin_44630050?t=1

    本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購(gòu)買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評(píng)論

    發(fā)表

    請(qǐng)遵守用戶 評(píng)論公約

    類似文章 更多