<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>오리</title>
    <link rel="stylesheet" href="styles.css">
</head>
<body>
    <div class="container">
        <h1>자유 게시판</h1>
        <div class="post-form">
            <h2>New Post</h2>
            <form id="postForm">
                <input type="text" id="username" placeholder="Your Name" required>
                <textarea id="content" placeholder="Write your post here..." required></textarea>
                <button type="submit">Post</button>
            </form>
        </div>
        <div class="posts" id="posts">
            <h2>Posts</h2>
            <!-- Posts will be added here dynamically -->
        </div>
    </div>
    <script src="script.js"></script>
</body>
</html>






body {
    font-family: Arial, sans-serif;
    background-color: #f4f4f4;
    margin: 0;
    padding: 20px;
}

.container {

    margin: auto;
    background: white;
    padding: 20px;
    border-radius: 5px;
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}

h1, h2 {
    color: #333;
}

.post-form {
    margin-bottom: 20px;
}

textarea {
    width: 100%;
    height: 100px;
    margin-top: 10px;
}

button {
    margin-top: 10px;
    padding: 10px 15px;
    background-color: #5cb85c;
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
}

button:hover {
    background-color: #4cae4c;
}

.post {
    border: 1px solid #ddd;
    padding: 10px;
    margin-top: 10px;
    border-radius: 5px;
}







document.getElementById('postForm').addEventListener('submit', function(event) {
    event.preventDefault(); // Prevent the form from submitting the traditional way

    const username = document.getElementById('username').value;
    const content = document.getElementById('content').value;

    // Create a new post element
    const post = document.createElement('div');
    post.classList.add('post');
    post.innerHTML = `<strong>${username}</strong><p>${content}</p>`;

    // Add the new post to the posts section
    document.getElementById('posts').appendChild(post);

    // Clear the form
    document.getElementById('postForm').reset();
});





이렇게 forum.html styles.css script.js 만들고 페이지 열엇더니


글 작성은 되는데ㅔ


왜 페이지 새로고침 하면 글 다 날라감?