<!DOCTYPEhtml><htmllang="en"><head><metacharset="UTF-8"><metaname="viewport"content="width=device-width, initial-scale=1.0"><title>Comment List with Reply Form</title><style>#comment-section{margin-bottom: 20px;}.comment{margin-bottom: 15px;padding: 10px;border: 1px solid #ccc;border-radius: 5px;}.reply-form{margin-top: 10px;}.reply-form textarea{width: 100%;height: 60px;margin-bottom: 10px;}#bottom-reply-form{margin-top: 20px;padding: 10px;border: 1px solid #ccc;border-radius: 5px;}#bottom-reply-form textarea{width: 100%;height: 60px;margin-bottom: 10px;}</style></head><body><divid="comment-section"><divclass="comment"><p>This is a comment.</p><buttonclass="reply-btn">回复</button></div><divclass="comment"><p>This is another comment.</p><buttonclass="reply-btn">回复</button></div></div><formid="bottom-reply-form"><textareaplaceholder="Write your reply..."></textarea><buttontype="submit">Submit</button></form><script>document.addEventListener('DOMContentLoaded',function(){const replyButtons =document.querySelectorAll('.reply-btn');const replyForm =document.getElementById('bottom-reply-form');let originalParent = replyForm.parentElement;// Store the original parent of the reply form
replyButtons.forEach(button=>{
button.addEventListener('click',function(){if(this.textContent==='取消'){// If the button text is "Cancel", move the form back to the bottom
originalParent.appendChild(replyForm);this.textContent='回复';}else{// Otherwise, move the form to the clicked comment
replyButtons.forEach(btn=>{if(btn !==this){// Reset other buttons to "Reply"
btn.textContent='回复';if(btn.parentElement.classList.contains('comment')&& btn.nextElementSibling=== replyForm){
originalParent.appendChild(replyForm);}}});// Move the form to the clicked commentif(replyForm.parentElement.classList.contains('comment')){// If the form is already in a comment, move it back to the bottom
originalParent.appendChild(replyForm);}this.parentNode.appendChild(replyForm);this.textContent='取消';}});});});</script></body></html>