回覆評論寫法

html部分:html

<body>
<h1>添加評論</h1>
<ul id="comments">
<li>你好</li>
<li>hello</li>
</ul>
<textarea id="textarea" rows="8" cols="40"></textarea>
<br>
<button id="submit">提交評論</button>
<script src="./js/添加評論.js"></script>
</body>

JS部分:
var button = document.getElementById('submit');var textarea = document.getElementById('textarea');var ul = document.getElementById('comments');button.onclick = function() {  var commentText = textarea.value;  appendComment(commentText);  clearTextarea();};function appendComment(text) {  var newComment = document.createElement('li');  newComment.innerHTML = text;  ul.appendChild(newComment);}function clearTextarea() {  textarea.value = '';}
相關文章
相關標籤/搜索