升平网络

 找回密码
 立即注册

快捷登录

查看: 903|回复: 0

一个漂亮的带搜索框文章列表页 html代码

[复制链接]

52

主题

58

帖子

346

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
346
发表于 2025-3-18 10:17:40 | 显示全部楼层 |阅读模式

这是一个创建于2025-3-18 10:17的主题,其中的信息可能已经有所发展或是发生改变。

  1. <!DOCTYPE html>
  2. <html lang="zh">
  3. <head>
  4.     <meta charset="UTF-8">
  5.     <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6.     <title>文章列表</title>
  7.     <style>
  8.     body {
  9.     font-family: Arial, sans-serif;
  10.     background-color: #f4f4f9;
  11.     margin: 0;
  12.     padding: 0;
  13. }

  14. .container {
  15.     width: 80%;
  16.     margin: auto;
  17.     overflow: hidden;
  18. }

  19. h1 {
  20.     text-align: center;
  21.     color: #333;
  22. }

  23. #searchInput {
  24.     width: 100%;
  25.     padding: 10px;
  26.     margin: 20px 0;
  27.     font-size: 16px;
  28.     border: 1px solid #ccc;
  29.     border-radius: 5px;
  30. }

  31. #articleList {
  32.     list-style-type: none;
  33.     padding: 0;
  34. }

  35. #articleList li {
  36.     background-color: white;
  37.     margin: 10px 0;
  38.     padding: 15px;
  39.     border-radius: 5px;
  40.     box-shadow: 0 2px 5px rgba(0,0,0,0.1);
  41. }
  42.     </style>
  43. </head>
  44. <body>
  45.     <div class="container">
  46.         <h1>文章列表</h1>
  47.         <input type="text" id="searchInput" placeholder="搜索文章..." onkeyup="searchArticles()">
  48.         <ul id="articleList">
  49.             <li>文章标题 1 - 内容摘要...</li>
  50.             <li>文章标题 2 - 内容摘要...</li>
  51.             <li>文章标题 3 - 内容摘要...</li>
  52.             <!-- 更多文章 -->
  53.         </ul>
  54.     </div>
  55.     <script>
  56.     function searchArticles() {
  57.     const input = document.getElementById('searchInput').value.toLowerCase();
  58.     const listItems = document.querySelectorAll('#articleList li');
  59.     listItems.forEach(item => {
  60.         const text = item.textContent.toLowerCase();
  61.         if (text.includes(input)) {
  62.             item.style.display = ""; // 或者使用 'block',取决于你的CSS设置。如果已经是block,则不需要更改。
  63.         } else {
  64.             item.style.display = "none"; // 如果未包含输入,则隐藏项目。
  65.         }
  66.     });
  67. }
  68.     </script>
  69. </body>
  70. </html>
复制代码
打赏鼓励一下!
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|小黑屋|升平网络 ( 鄂ICP备18029072号 )|网站地图

GMT+8, 2025-5-5 00:13 , Processed in 0.209257 second(s), 24 queries .

Powered by Discuz! X3.4

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表