原生js驗(yàn)證簡(jiǎn)潔注冊(cè)登錄頁(yè)面
序
一個(gè)以js驗(yàn)證表單的簡(jiǎn)潔的注冊(cè)登錄頁(yè)面,不多說(shuō)直接上圖
效果
主要文件
完整代碼
1 sign_up.html 注冊(cè)表單
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>sign-up</title> <link rel="stylesheet" href="css/common_form.css"> </head> <body> <header> <div class="header-line"></div> </header> <div class="content"> <img class="content-logo" src="img/form_logo.png" alt="logo"> <h1 class="content-title">創(chuàng)建賬戶</h1> <div class="content-form"> <form method="post" action="" onsubmit="return submitTest()"> <div id="change_margin_1"> <input class="user" type="text" name="user" placeholder="請(qǐng)輸入用戶名" onblur="oBlur_1()" onfocus="oFocus_1()"> </div> <!-- input的value為空時(shí)彈出提醒 --> <p id="remind_1"></p> <div id="change_margin_2"> <input class="password" type="password" name="password" placeholder="請(qǐng)輸入密碼" onblur="oBlur_2()" onfocus="oFocus_2()"> </div> <!-- input的value為空時(shí)彈出提醒 --> <p id="remind_2"></p> <div id="change_margin_3"> <input class="content-form-signup" type="submit" value="創(chuàng)建賬戶"> </div> </form> </div> <div class="content-login-description">已經(jīng)擁有賬戶?</div> <div><a class="content-login-link" href="log_in.html">登錄</a></div> </div> <script src="js/common_form_test.js"></script> </body> </html>
2 log_in.html 登錄表單
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>log-in</title> <link rel="stylesheet" href="css/common_form.css"> </head> <body> <header> <div class="header-line"></div> </header> <div class="content"> <img class="content-logo" src="img/form_logo.png" alt="logo"> <h1 class="content-title">登錄</h1> <div class="content-form"> <form method="post" action="" onsubmit="return submitTest()"> <div id="change_margin_1"> <input class="user" type="text" name="user" placeholder="請(qǐng)輸入用戶名" onblur="oBlur_1()" onfocus="oFocus_1()"> </div> <!-- input的value為空時(shí)彈出提醒 --> <p id="remind_1"></p> <div id="change_margin_2"> <input class="password" type="password" name="password" placeholder="請(qǐng)輸入密碼" onblur="oBlur_2()" onfocus="oFocus_2()"> </div> <!-- input的value為空時(shí)彈出提醒 --> <p id="remind_2"></p> <div id="change_margin_3"> <input class="content-form-signup" type="submit" value="登錄"> </div> </form> </div> <div class="content-login-description">沒(méi)有賬戶?</div> <div><a class="content-login-link" href="sign_up.html">注冊(cè)</a></div> </div> <script src="js/common_form_test.js"></script> </body> </html>
3 common_form.css 表單css樣式
/*重置樣式*/ html, body, div, span, applet, object, iframe, h1, h2, h3, h4, h5, h6, p, blockquote, pre, a, abbr, acronym, address, big, cite, code, del, dfn, em, img, ins, kbd, q, s, samp, small, strike, strong, sub , sup, tt, var, b, u, i, dl, dt, dd, ol, ul, li, fieldset, form, label, legend, table, caption, tbody, tfoot, thead, tr, th, td, article, aside, canvas, details, embed, figure, figcaption, footer, header, hgroup, menu, nav, output, section, summary, time, mark, audio, video { margin: 0; padding: 0; border: 0 } body { font-family: "微軟雅黑"; background: #f4f4f4; } /*header*/ .header-line { width: 100%; height: 4px; background: #0dbfdd; } /*content*/ .content { width: 28%; margin: 70px auto 0; text-align: center; } .content-logo { width: 80px; height: 80px; } .content-title { margin: 10px 0 25px 0; font-size: 2em; color: #747474; font-weight: normal; } .content-form { width: 100%; padding: 36px 0 20px; border: 1px solid #dedede; text-align: center; background: #fff; } .content-form form div { margin-bottom: 19px; } .content-form form .user, .content-form form .password { width: 77%; height: 20px; padding: 10px; font-size: 1em; border: 1px solid #cccbcb; border-radius: 7px; letter-spacing: 1px; } .content-form form input:focus { outline: none; -webkit-box-shadow: 0 0 5px #0dbfdd; box-shadow: 0 0 5px #0dbfdd; } .content-form-signup { width: 84%; margin: 0 auto; padding: 10px; border: 1px solid #cccbcb; border-radius: 7px; font-size: 1em; font-weight: bold; color: #fff; background: #0dbfdd; cursor: pointer; } .content-form-signup:hover { background: #0cb3d0; } .content-form-signup:focus { outline: none; border: 1px solid #0cb3d0; } .content-login-description { margin-top: 25px; line-height: 1.63636364; color: #747474; font-size: .91666667rem; } .content-login-link { font-size: 16px; color: #0dbfdd; text-decoration: none; } /*輸入框無(wú)內(nèi)容便提示*/ #remind_1, #remind_2 { width: 76%; margin: 0 auto 2px; text-align: left; font-size: .2em; color: #f00; }
4 common_form_test.js 注冊(cè)登錄腳本
// 全局變量a和b,分別獲取用戶框和密碼框的value值 var a = document.getElementsByTagName("input")[0].value; var b = document.getElementsByTagName("input")[1].value; //用戶框失去焦點(diǎn)后驗(yàn)證value值 function oBlur_1() { if (!a) { //用戶框value值為空 document.getElementById("remind_1").innerHTML = "請(qǐng)輸入用戶名!"; document.getElementById("change_margin_1").style.marginBottom = 1 + "px"; } else { //用戶框value值不為空 document.getElementById("remind_1").innerHTML = ""; document.getElementById("change_margin_1").style.marginBottom = 19 + "px"; } } //密碼框失去焦點(diǎn)后驗(yàn)證value值 function oBlur_2() { if (!b) { //密碼框value值為空 document.getElementById("remind_2").innerHTML = "請(qǐng)輸入密碼!"; document.getElementById("change_margin_2").style.marginBottom = 1 + "px"; document.getElementById("change_margin_3").style.marginTop = 2 + "px"; } else { //密碼框value值不為空 document.getElementById("remind_2").innerHTML = ""; document.getElementById("change_margin_2").style.marginBottom = 19 + "px"; document.getElementById("change_margin_3").style.marginTop = 19 + "px"; } } //用戶框獲得焦點(diǎn)的隱藏提醒 function oFocus_1() { document.getElementById("remind_1").innerHTML = ""; document.getElementById("change_margin_1").style.marginBottom = 19 + "px"; } //密碼框獲得焦點(diǎn)的隱藏提醒 function oFocus_2() { document.getElementById("remind_2").innerHTML = ""; document.getElementById("change_margin_2").style.marginBottom = 19 + "px"; document.getElementById("change_margin_3").style.marginTop = 19 + "px"; } //若輸入框?yàn)榭?,阻止表單的提? function submitTest() { if (!a && !b) { //用戶框value值和密碼框value值都為空 document.getElementById("remind_1").innerHTML = "請(qǐng)輸入用戶名!"; document.getElementById("change_margin_1").style.marginBottom = 1 + "px"; document.getElementById("remind_2").innerHTML = "請(qǐng)輸入密碼!"; document.getElementById("change_margin_2").style.marginBottom = 1 + "px"; document.getElementById("change_margin_3").style.marginTop = 2 + "px"; return false; //只有返回true表單才會(huì)提交 } else if (!a) { //用戶框value值為空 document.getElementById("remind_1").innerHTML = "請(qǐng)輸入用戶名!"; document.getElementById("change_margin_1").style.marginBottom = 1 + "px"; return false; } else if (!b) { //密碼框value值為空 document.getElementById("remind_2").innerHTML = "請(qǐng)輸入密碼!"; document.getElementById("change_margin_2").style.marginBottom = 1 + "px"; document.getElementById("change_margin_3").style.marginTop = 2 + "px"; return false; } }
5 form_logo.png Logo照片
到這里,一個(gè)簡(jiǎn)單的注冊(cè)登錄頁(yè)面就完成了,后面會(huì)持續(xù)更新,使之更強(qiáng)大。
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
低門檻開(kāi)發(fā)iOS、Android、小程序應(yīng)用的前端框架詳解
結(jié)合AVM官網(wǎng)的介紹和我自己的一些實(shí)踐經(jīng)驗(yàn),我總結(jié)了一系列AVM的特性,我想這些內(nèi)容足以讓你主動(dòng)去學(xué)習(xí)AVM框架了2021-10-10easyui combobox開(kāi)啟搜索自動(dòng)完成功能的實(shí)例代碼
下面小編就為大家?guī)?lái)一篇easyui combobox開(kāi)啟搜索自動(dòng)完成功能的實(shí)例代碼。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2016-11-11非jQuery實(shí)現(xiàn)照片散落桌子上,單擊放大的LightBox效果
本文給大家介紹一款js實(shí)現(xiàn)的照片散落桌子上點(diǎn)擊放大圖片的LightBox效果,非常的炫酷,而且是非jQuery實(shí)現(xiàn)的,有需要的小伙伴可以參考下2014-11-11JS+cookie實(shí)現(xiàn)購(gòu)物評(píng)價(jià)五星好評(píng)功能
這篇文章主要為大家詳細(xì)介紹了JS+cookie實(shí)現(xiàn)購(gòu)物評(píng)價(jià)五星好評(píng)功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-09-09基于JavaScript實(shí)現(xiàn)快速轉(zhuǎn)換文本語(yǔ)言(繁體中文和簡(jiǎn)體中文)
這篇文章主要介紹了基于JavaScript實(shí)現(xiàn)快速切換正體中文和簡(jiǎn)體中文,需要的朋友可以參考下2016-03-03無(wú)間斷滾動(dòng)的新聞文章列表,兼容IE、Firefox和Opera,符合W3C標(biāo)準(zhǔn)??勺鱉arquee
無(wú)間斷滾動(dòng)的新聞文章列表,兼容IE、Firefox和Opera,符合W3C標(biāo)準(zhǔn)??勺鱉arquee...2007-05-05微信小程序wx.request實(shí)現(xiàn)后臺(tái)數(shù)據(jù)交互功能分析
這篇文章主要介紹了微信小程序wx.request實(shí)現(xiàn)后臺(tái)數(shù)據(jù)交互功能,分析微信小程序wx.request在后臺(tái)數(shù)據(jù)交互過(guò)程中遇到的問(wèn)題與相關(guān)的解決方法,需要的朋友可以參考下2017-11-11