JS實(shí)現(xiàn)用戶(hù)注冊(cè)界面功能
本文實(shí)例為大家分享了JS實(shí)現(xiàn)用戶(hù)注冊(cè)界面功能的具體代碼,供大家參考,具體內(nèi)容如下
1.css代碼
*{ margin: 0; padding: 0; } .block{ position: relative; margin: 0 auto; margin-top: 80px; width: 710px; height: 500px; border: 1px solid rgba(29, 29, 29, 0.64); background: url("./img/logo2396.jpg")no-repeat; background-size: 100%; } .photo { position: absolute; z-index: 1; width: 710px; height: 500px; background-color: rgba(0, 0, 0, 0.71); } .biao{ margin-top: 20px; position: absolute; z-index: 2; margin-left: 150px; } li{ position: relative; padding-left:20px ; list-style: none; line-height: 70px; width: 400px; border: 1px solid white; margin:5px auto; } li input[type=text]{ padding-left: 20px; border-style: none; background: none; } input[type=submit]{ margin-left: 150px; border-style: none; font-size: 25px; color: white; background: none; } .d{ background-color: rgba(222, 53, 3, 0.71); } .txt{ line-height: 50px; width: 280px; font-size: 15px; color: white; } .error { position: absolute; z-index: 2; left: 150px; color: rgba(253, 253, 253, 0.4); font-size: 14px; }
2.html代碼
<div class="block"> <div class="photo"></div> <div class="biao"> <form name="form"> <ul> <li><label style="color: white">賬 號(hào):</label><input class="txt" type="text"></li> <li><label style="color: white">密 碼:</label><input class="txt" type="text"></li> <li><label style="color: white">確認(rèn)密碼:</label><input class="txt" type="text"></li> <li><label style="color: white">電話號(hào)碼:</label><input class="txt" type="text"></li> <li><label style="color: white">郵 箱:</label><input class="txt" type="text"></li> <li class="d"><input id="sub" type="submit" value="注冊(cè)"></li> </ul> </form> </div> </div>
3.js代碼
var sub=document.getElementById("sub"); var txt=document.getElementsByClassName("txt"); var li=document.getElementsByTagName("li"); document.forms.form.onsubmit=function(){ yan(); var errl=document.getElementsByClassName("error").length; if(!errl){ return true; } return false; }; function yan(){ for(var i=0;i<txt.length;i++){ txt[i].focus(); } sub.focus(); } for(var i=0;i<txt.length;i++) { txt[i].index=i; txt[i].onfocus=function (){ if(this.parentElement.children[2]==undefined) return; this.parentElement.children[2].remove(); }; txt[i].onblur=function (){ switch (this.index){ case 0: if(this.value==""){ var s=document.createElement("span"); s.innerHTML="請(qǐng)輸入賬號(hào)"; s.className="error"; li[this.index].appendChild(s) } else{ var s=document.createElement("span"); s.innerHTML=""; s.className="sucess"; li[this.index].appendChild(s) } break; case 1: if(this.value==""){ var s=document.createElement("span"); s.innerHTML="請(qǐng)輸入密碼"; s.className="error"; li[this.index].appendChild(s) } else if(this.value.length<6||this.value.length>11) { var s=document.createElement("span"); s.innerHTML="密碼錯(cuò)誤"; s.className="error"; li[this.index].appendChild(s); txt[this.index].value=""; } else{ var s=document.createElement("span"); s.innerHTML=""; s.className="sucess"; li[this.index].appendChild(s) } break; case 2: if(this.value==""){ var s=document.createElement("span"); s.innerHTML="請(qǐng)?jiān)俅未_認(rèn)密碼"; s.className="error"; li[this.index].appendChild(s); txt[this.index].value=""; } else if(this.value!=txt[1].value){ var s=document.createElement("span"); s.innerHTML="請(qǐng)重新輸入"; s.className="error"; li[this.index].appendChild(s); txt[this.index].value=""; } else{ var s=document.createElement("span"); s.innerHTML=""; s.className="sucess"; li[this.index].appendChild(s) } break; case 3: if(this.value==""){ var s=document.createElement("span"); s.innerHTML="請(qǐng)輸入號(hào)碼"; s.className="error"; li[this.index].appendChild(s) } else if(this.value.length!=11){ var s=document.createElement("span"); s.innerHTML="號(hào)碼格式錯(cuò)誤"; s.className="error"; li[this.index].appendChild(s) txt[this.index].value=""; } else{ var s=document.createElement("span"); s.innerHTML=""; s.className="sucess"; li[this.index].appendChild(s) } break; case 4: if(this.value==""){ var s=document.createElement("span"); s.innerHTML="請(qǐng)輸入郵箱"; s.className="error"; li[this.index].appendChild(s) } else{ var s=document.createElement("span"); s.innerHTML=""; s.className="sucess"; li[this.index].appendChild(s) } break; } } }
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
javascript表格控件:Chgrid,簡(jiǎn)化型
javascript表格控件:Chgrid,簡(jiǎn)化型...2007-04-04JavaScript 計(jì)算圖片加載數(shù)量的代碼
先定義一個(gè)圖片的數(shù)組,然后通過(guò)image的onload事件來(lái)計(jì)算,注意,onload在ie和火狐有所不同。2011-01-01JS 實(shí)現(xiàn)隨機(jī)驗(yàn)證碼功能
驗(yàn)證碼驗(yàn)證是網(wǎng)頁(yè)常出現(xiàn)的一個(gè)驗(yàn)證點(diǎn),所謂驗(yàn)證碼類(lèi)型有很多,下面代碼只是實(shí)現(xiàn)一個(gè)簡(jiǎn)單的驗(yàn)證功能,需要的朋友參考下2017-02-02用簡(jiǎn)單的腳本實(shí)現(xiàn)一款漂亮的下拉菜單
用簡(jiǎn)單的腳本實(shí)現(xiàn)一款漂亮的下拉菜單...2006-12-12解決layui 復(fù)選框等內(nèi)置控件不顯示的問(wèn)題
今天小編就為大家分享一篇解決layui 復(fù)選框等內(nèi)置控件不顯示的問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2018-08-08uni-app和web-view頁(yè)面相互傳參方法實(shí)例
web-view是一個(gè)web瀏覽器組件,可以用來(lái)承載網(wǎng)頁(yè)的容器,會(huì)自動(dòng)鋪滿整個(gè)頁(yè)面,下面這篇文章主要給大家介紹了關(guān)于uni-app和web-view頁(yè)面相互傳參的相關(guān)資料,需要的朋友可以參考下2023-06-06JavaScript 異步調(diào)用框架 (Part 1 - 問(wèn)題 & 場(chǎng)景)
在Ajax應(yīng)用中,調(diào)用XMLHttpRequest是很常見(jiàn)的情況。特別是以客戶(hù)端為中心的Ajax應(yīng)用,各種需要從服務(wù)器端獲取數(shù)據(jù)的操作都通過(guò)XHR異步調(diào)用完成。2009-08-08