评论框

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style>
.comments {
text-align: right;
}
.container {
width: 250px;
}
textarea {
resize: none;
overflow: hidden;
width: 250px;
height: 100px;
}
.second {
display: none;
}
</style>
</head>
<body>
<div class="container">
<p>范冰冰:李晨好帅~O(∩_∩)O~</p>
<p class="comments"><button id="commentsBtn">评论</button></p>
</div>
<div id="commentsPanel" class="container second">
<div><textarea id="inputInfo"></textarea></div>
<div class="comments"><button id="submit">提交</button></div>
<ul id="commentsItem"></ul>
</div>
<script>
var open = false;
var commentsBtnEle = document.getElementById("commentsBtn");
commentsBtnEle.onclick = function() {
var commentsPanelEle = document.getElementById("commentsPanel");
if (open) {
commentsPanelEle.style.display = "none";
open = false;
} else {
commentsPanelEle.style.display = "block";
open = true;
}
}
var submitEle = document.getElementById("submit");
submitEle.onclick = function() {
var inputInfoEle = document.getElementById("inputInfo");
var val = inputInfoEle.value;
var commentsItemEle = document.getElementById("commentsItem");
var liEle = document.createElement("li");
liEle.innerHTML = "妙语连珠:" + val;
if (commentsItemEle.childNodes.length === 0) {
commentsItemEle.appendChild(liEle);
} else {
commentsItemEle.insertBefore(liEle, commentsItemEle.childNodes[0]);
}
}
</script>
</body>
</html>

posted @ 2016-06-10 19:18  顾锦书-王丹  阅读(272)  评论(0编辑  收藏  举报