開發者們大家好!我很高興分享我的最新項目:時事通訊註冊表。該專案非常適合那些希望創建一個實用且具有視覺吸引力的表單的人,該表單可以使用 HTML、CSS 和 JavaScript 收集新聞通訊的使用者電子郵件地址。這是增強前端開發技能和建立管理訂閱的有用工具的好方法。
新聞通訊註冊表是一個網絡應用程序,旨在允許用戶訂閱新聞通訊。該表單包括電子郵件驗證,並在成功訂閱後顯示成功訊息。本專案採用簡潔且互動的設計,示範如何建立實用且使用者友善的表單。
以下是項目結構的概述:
Newsletter-Signup-Form/ ├── index.html ├── style.css └── script.js
要開始該項目,請按照以下步驟操作:
複製儲存庫:
git clone https://github.com/abhishekgurjar-in/Newsletter-Signup-Form.git
開啟專案目錄:
cd Newsletter-Signup-Form
運行項目:
index.html 檔案定義電子報註冊表單的結構,包括輸入欄位、按鈕和結果顯示區域。這是一個片段:
8b05045a5be5764f313ed5b9168a17e6 49099650ebdc5f3125501fa170048923 93f0f5c25f18dab9d176bd4f6de5d30e 1fc2df4564f5324148703df3b6ed50c1 4f2fb0231f24e8aef524fc9bf9b9874f b2386ffb911b14667cb8f0f91ea547a7Newsletter Signup Form6e916e0f7d1e588d4f442bf645aedb2f a565cfc5beb6e6a8c6ba642934395a39 468dcf7b0ee61aef03af1a1fbe6725fc 5de102113aede4703971b3b780c58efb2cacc6d41bbb37262a98f745aa00fbf0 9c3bca370b5104690d9ef395f2c5f8d1 6c04bd5ca3fcae76e30b72ad730ca86d 4883ec0eb33c31828b7c767c806e14c7 8f9e4409b06fde1ff1d3a80f075ca0ed 641e0de5ce410c86c3a093b6b324b956 4a249f0d628e2318394fd9b75b4636b1Stay Updated!473f0a7621bec819994bb5020d29372a e388a4556c0f65e1904146cc1a846beeJoin our mailing list to receive updates and promotions.94b3e26ee717c64999d7867364b1b4a3 9c1c3883d21d24a82adc94e97e20713b e388a4556c0f65e1904146cc1a846beeEmail Address94b3e26ee717c64999d7867364b1b4a3 f50061566a3685479c7d3b0d5d936071Valid Email Required94b3e26ee717c64999d7867364b1b4a3 16b28748ea4df4d9c2150843fecfba68 ff9c23ada1bcecdd1a0fb5d5a0f18437 281932a54b782c94d20ff8498db12891 169513d93b292361c90c726f0b3ca858 f5a47148e367a6035fd7a2faa965022e 16b28748ea4df4d9c2150843fecfba68 b33314c2aece6845b814e24426768d58 28ffba8a7704d9573fe0b1c02c12376a 16b28748ea4df4d9c2150843fecfba68 16b28748ea4df4d9c2150843fecfba68 16b28748ea4df4d9c2150843fecfba68 ffd6ba4147bda351239915f463e46e38 e388a4556c0f65e1904146cc1a846beeMade with ❤️ by Abhishek Gurjar94b3e26ee717c64999d7867364b1b4a3 16b28748ea4df4d9c2150843fecfba68 36cc49f0c466276486e50c850b7e4956 73a6ac4ed44ffec12cee46588e518a5e
style.css 檔案對電子報註冊表單進行樣式設計,使其更具吸引力且易於使用。以下是一些關鍵樣式:
* { box-sizing: border-box; } body { font-family: Roboto, sans-serif; margin: 0; padding: 0; background-color: #36384e; } .container { max-width: 1240px; margin: 0 auto; } .box { gap: 20px; max-width: 70%; display: flex; align-items: center; justify-content: center; margin-top: 30px; margin-inline: auto; background-color: white; border-radius: 15px; } .left-box { margin: 20px; width: 50%; } .left-box h1 { font-size: 50px; } .left-box p { font-size: 20px; } .email-text { display: flex; align-items: center; justify-content: center; } .success { display: inline; } .success-icon { width: 27px; } .email-text { display: flex; align-items: center; justify-content: space-between; } .not-valid { color: red; display: none; } input { font-size: 20px; width: 100%; height: 50px; border-radius: 15px; border: 2px solid black; } .button { font-size: 20px; width: 100%; border-radius: 15px; background-color: #242742; color: white; } .button:hover { background-color: #ff644b; cursor: pointer; } .right-box { width: 50%; margin: 0 20px; } .right-box img { width: 100%; } .footer { color: white; margin: 30px; text-align: center; } @media (max-width: 1200px) { .box { flex-direction: column-reverse; } }
script.js 檔案包含處理電子郵件驗證和顯示成功訊息的邏輯。這是一個片段:
const submitBtn = document.getElementsByClassName("button")[0]; const emailInput = document.getElementsByClassName("email-input")[0]; const error = document.getElementsByClassName("not-valid")[0]; const box = document.getElementsByClassName("box")[0]; submitBtn.addEventListener("click", (event) => { event.preventDefault(); const emailPattern = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/; const isValid = emailPattern.test(emailInput.value); if (!isValid) { error.style.display = "block"; } else { error.style.display = "none"; // Hide the error message if email is valid box.style.display = "none"; // Create and show the message const message = document.createElement("div"); message.className = "message"; message.innerHTML = ` 938598788b30f248187d965791fed44f d06cde061393e4022fbb4cd7cf443567 4a249f0d628e2318394fd9b75b4636b1Thanks for subscribing!473f0a7621bec819994bb5020d29372a e388a4556c0f65e1904146cc1a846bee A confirmation email has been sent to ${emailInput.value}. Please open it and click the button inside to confirm your subscription. 94b3e26ee717c64999d7867364b1b4a3 3ce38003a7ba6de8604d8636abf55d8fDismiss message2e9b454fa8428549ca2e64dfac4625cd 16b28748ea4df4d9c2150843fecfba68`; // Append the message to the body document.body.appendChild(message); // Select the close button from the newly created message element const closeBtn = message.querySelector(".closeBtn"); closeBtn.addEventListener("click", () => { message.remove(); location.reload(); // Reload the website }); } });
您可以在此處查看時事通訊註冊表專案的現場演示。
建立時事通訊註冊表單是應用前端開發技能來建立實用且引人入勝的工具的絕佳方法。此專案示範如何建立可用於管理電子郵件訂閱的互動式回應表單。我希望它能激勵您建立自己的工具並提高您的 Web 開發技能。快樂編碼!
這個專案是我在 Web 開發方面持續學習之旅的一部分。
以上是建立時事通訊註冊表單網站的詳細內容。更多資訊請關注PHP中文網其他相關文章!