|
这是一个创建于2025-3-18 10:17的主题,其中的信息可能已经有所发展或是发生改变。
- <!DOCTYPE html>
- <html lang="zh">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>文章列表</title>
- <style>
- body {
- font-family: Arial, sans-serif;
- background-color: #f4f4f9;
- margin: 0;
- padding: 0;
- }
-
- .container {
- width: 80%;
- margin: auto;
- overflow: hidden;
- }
-
- h1 {
- text-align: center;
- color: #333;
- }
-
- #searchInput {
- width: 100%;
- padding: 10px;
- margin: 20px 0;
- font-size: 16px;
- border: 1px solid #ccc;
- border-radius: 5px;
- }
-
- #articleList {
- list-style-type: none;
- padding: 0;
- }
-
- #articleList li {
- background-color: white;
- margin: 10px 0;
- padding: 15px;
- border-radius: 5px;
- box-shadow: 0 2px 5px rgba(0,0,0,0.1);
- }
- </style>
- </head>
- <body>
- <div class="container">
- <h1>文章列表</h1>
- <input type="text" id="searchInput" placeholder="搜索文章..." onkeyup="searchArticles()">
- <ul id="articleList">
- <li>文章标题 1 - 内容摘要...</li>
- <li>文章标题 2 - 内容摘要...</li>
- <li>文章标题 3 - 内容摘要...</li>
- <!-- 更多文章 -->
- </ul>
- </div>
- <script>
- function searchArticles() {
- const input = document.getElementById('searchInput').value.toLowerCase();
- const listItems = document.querySelectorAll('#articleList li');
- listItems.forEach(item => {
- const text = item.textContent.toLowerCase();
- if (text.includes(input)) {
- item.style.display = ""; // 或者使用 'block',取决于你的CSS设置。如果已经是block,则不需要更改。
- } else {
- item.style.display = "none"; // 如果未包含输入,则隐藏项目。
- }
- });
- }
- </script>
- </body>
- </html>
复制代码 |
|