【JAVA-S2阶段】JavaScript论坛发言

<!DOCTYPE html>
<html>

<head lang="en">
    <meta charset="UTF-8">
    <title>课工场论坛列表</title>
    <link href="css/bbs.css" rel="stylesheet">
    <script type="text/javascript">

        function show() {
            document.getElementsByClassName("post")[0].style.display = "block";
            var select = document.getElementsByTagName("select")[0];
            select.selectedIndex = "";
            var title = document.getElementsByClassName("title")[0];
            title.value = "";
            var textareas = document.getElementsByTagName("textarea")[0];
            textareas.value = " ";
        }
        function issue() {
            var imgArr = ["images/tou02.jpg", "images/tou01.jpg", "images/tou03.jpg", "images/tou04.jpg"];
            var liC = document.getElementById("create");
            document.getElementsByClassName("post")[0].style.display = "none";
            var li = document.createElement("li");
            li.setAttribute("class", "create-div-h1-p");
            //var liN = document.getElementsByClassName("create - div - h1 - p");
            var div = document.createElement("div");
            var img = document.createElement("img");
            var num = parseInt(Math.floor(Math.random() * 4));
            img.setAttribute("src", imgArr[num]);
            //liC.insertBefore(liN[linum += 1], )
            var h1 = document.createElement("h1");
            var p = document.createElement("p");
            var span = document.createElement("span");
            liC.appendChild(li);
            li.appendChild(div);
            li.appendChild(h1);
            li.appendChild(p);
            div.appendChild(img);
            //定义一个时间类
            var time = new Date();
            var text = " ";
            text += time.getFullYear() + "年";
            text += time.getMonth() + 1 + "月";
            text += time.getDate() + "日";
            text += time.getHours() + ":";
            text += time.getMinutes() + ":";
            text += time.getSeconds();
            //获取title对象,并且获取对应的值
            var title = document.getElementsByClassName("title")[0];
            h1.innerHTML = title.value;
            //获取下拉框的对象,再获取对应的值
            var select = document.getElementsByTagName("select")[0];
            p.innerHTML = "板块:  " + select.value;
            span.innerHTML = "时间:" + text;
            //先创建p节点对象,再将需要的值赋值给span标签之后,才可以将span追加到p标签下
            p.appendChild(span);
            //获取textarea的对象,并且获取对应的值
            // var textareas = document.getElementsByTagName("textarea")[0];
            // alert(textareas.value);
            //使用childNodes时候,注意空格,空格也算子集
            if (document.getElementById("create").childNodes.length != 0) {
                document.getElementById("create").insertBefore(li, document.getElementById("create").childNodes[0]);
            }
        }

    </script>
</head>

<body>

    <div class="bbs">
        <header>
            <span onclick="show()">我要发帖</span>
        </header>
        <section>
            <ul id="create"></ul>
        </section>
        <div class="post">
            <input class="title" placeholder="请输入标题(1-50个字符)">所属版块:
            <select>



                <option label="请选择版块" disabled="disabled" pleace>请选择板块</option>
                <option>电子书籍</option>
                <option>新课来了</option>
                <option>新手报到</option>
                <option>职业规划</option>
            </select>
            <textarea class="content"></textarea>
            <input class="btn" value="发布" onclick="issue(); ">
        </div>
    </div>
</body>

</html>

css

*{margin: 0; padding: 0; font-family: "Arial", "΢���ź�";}
ul,li{list-style: none;}
.bbs{margin: 0 auto; width: 600px; position: relative;}
header{padding: 5px 0; border-bottom: 1px solid #cecece;}
header span{display:inline-block; width: 220px; height: 50px; color: #fff; background: #009966; font-size: 18px; font-weight: bold; text-align: center;line-height: 50px; border-radius: 8px; cursor: pointer;}
.post{position: absolute; background: #ffffff; border: 1px #cccccc solid; width: 500px; left: 65px; top:70px; padding: 10px; font-size: 14px; z-index: 999999; display: none;}
.post .title{width: 450px; height:30px; line-height: 30px; display: block; border: 1px #cecece solid; margin-bottom: 10px;}
.post select{width: 200px; height: 30px;}
.post .content{width: 450px; height: 200px; display: block; margin: 10px 0;border: 1px #cecece solid;}
.post .btn{width: 160px; height: 35px; color: #fff; background: #009966; border: none; font-size: 14px; font-weight: bold; text-align: center; line-height: 35px; border-radius: 8px; cursor: pointer;}

.bbs section ul li{padding: 10px 0; border-bottom: 1px #999999 dashed;
    overflow: hidden; }
.bbs section ul li div{float: left; width: 60px; margin-right: 10px;}
.bbs section ul li div img{ border-radius:50%; width: 60px;}
.bbs section ul li h1{float: left; width: 520px; font-size: 16px; line-height: 35px;}
.bbs section ul li p{color: #666666; line-height: 25px; font-size: 12px; }
.bbs section ul li p span{padding-left:20px;}
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

你到底奶不奶我

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值