首页 前端知识 评论回复功能代码js html css

评论回复功能代码js html css

2024-03-23 13:03:47 前端知识 前端哥 237 844 我要收藏
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Comment Reply</title>
<style>
.comments {
margin-bottom: 20px;
}
.reply-form {
display: none;
margin-left: 20px;
}
</style>
<div class="comments">
<div class="comment">
<p>This is the first comment</p>
<button class="reply-btn">Reply</button>
<form class="reply-form">
<input type="text" placeholder="Enter your reply">
<button type="submit">Submit</button>
</form>
</div>
<div class="comment">
<p>This is the second comment</p>
<button class="reply-btn">Reply</button>
<form class="reply-form">
<input type="text" placeholder="Enter your reply">
<button type="submit">Submit</button>
</form>
</div>
<script>
const replyBtns = document.querySelectorAll('.reply-btn');
replyBtns.forEach(replyBtn => replyBtn.addEventListener('click', () => {
const replyForm = replyBtn.nextElementSibling;
if (replyForm.style.display === '' || replyForm.style.display === '') {
replyForm.style.display = 'block';
} else {
replyForm.style.display = 'none';
}
}));
</script>
</div>
复制
转载请注明出处或者链接地址:https://www.qianduange.cn//article/4062.html
标签
评论
发布的文章

JQuery中的load()、$

2024-05-10 08:05:15

大家推荐的文章
复制成功!