Skip to content
Closed

Hm1 #1467

Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 53 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,14 @@
type="text"
class="add-form-name"
placeholder="Введите ваше имя"
id="name"
/>
<textarea
type="textarea"
class="add-form-text"
placeholder="Введите ваш коментарий"
rows="4"
id="comments"
></textarea>
<div class="add-form-row">
<button class="add-form-button">Написать</button>
Expand All @@ -65,7 +67,57 @@

<script>
"use strict";
// Код писать здесь

const nameInput = document.getElementById("name");
const commentInput = document.getElementById("comments");

nameInput.addEventListener("input", () => {
console.log("Имя изменено");
});

commentInput.addEventListener("input", () => {
console.log("Комментарий изменен");
});

const addButton = document.querySelector(".add-form-button");
const commentsList = document.querySelector(".comments");

addButton.addEventListener("click", () => {
const name = nameInput.value;
const commentText = commentInput.value;

const now = new Date();
const day = String(now.getDate()).padStart(2, '0');
const month = String(now.getMonth() + 1).padStart(2, '0');
const year = String(now.getFullYear()).slice(-2);
const hours = String(now.getHours()).padStart(2, '0');
const minutes = String(now.getMinutes()).padStart(2, '0');
const currentDateTime = `${day}.${month}.${year} ${hours}:${minutes}`;

const newComment = `
<li class="comment">
<div class="comment-header">
<div>${name}</div>
<div>${currentDateTime}</div>
</div>
<div class="comment-body">
<div class="comment-text">
${commentText}
</div>
</div>
<div class="comment-footer">
<div class="likes">
<span class="likes-counter">0</span>
<button class="like-button"></button>
</div>
</div>
</li>
`;

commentsList.innerHTML += newComment;
});

console.log("It works!");
</script>
</html>

Loading