<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style>
.comments {
text-align: right;
}
.container {
250px;
}
textarea {
resize: none;
overflow: hidden;
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>