task-comp.html 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <style>
  5. /* 搜索栏CSS 样式 */
  6. .search-container {
  7. display: flex;
  8. align-items: center;
  9. width: 300px;
  10. }
  11. .search-input {
  12. flex: 1;
  13. padding: 8px;
  14. font-size: 16px;
  15. border: 1px solid #ccc;
  16. border-radius: 4px;
  17. }
  18. .search-input::placeholder {
  19. color: #999;
  20. opacity: 1;
  21. }
  22. .search-button {
  23. padding: 8px 12px;
  24. background-color: #4CAF50;
  25. color: white;
  26. font-size: 16px;
  27. border: none;
  28. border-radius: 4px;
  29. cursor: pointer;
  30. }
  31. </style>
  32. </head>
  33. <body>
  34. <div class="search-container">
  35. <input type="text" id="search-input" class="search-input" placeholder="Enter your search term">
  36. <button id="search-button" class="search-button">Search</button>
  37. </div>
  38. <script>
  39. // JavaScript 代码
  40. const searchButton = document.getElementById("search-button");
  41. const searchInput = document.getElementById("search-input");
  42. searchButton.addEventListener("click", function() {
  43. const searchTerm = searchInput.value;
  44. // 在这里执行搜索操作,可以根据需求进行相应的处理
  45. console.log("Search term:", searchTerm);
  46. });
  47. </script>
  48. </body>
  49. </html>