HTML
<div class="con">
<div class="top">
<p><img src="logo.jpg"></p>
</div>
<div class="bottom">
<p>
用戶名:<input type="text" placeholder="請輸入用戶名">
<span></span>
</p>
<p>
密碼:<input type="password" placeholder="請輸入密碼">
<span></span>
</p>
<p>
郵箱:<input placeholder="請輸入郵箱">
<span></span>
</p>
<p>
請確認(rèn)密碼:<input type="password" placeholder="請輸入密碼">
<span></span>
</p>
<p>
請輸入手機(jī)號:<input type="text" placeholder="請輸入密碼">
<span></span>
<img src="sprite.png"/>
</p>
</div>
</div>
css樣式
<style type="text/css">
*{
padding: 0;
margin: 0;
}
.con{
margin:100px auto;
height:500px;
width:500px;
border:1px solid #000;
}
.top{
padding-bottom: 30px;
border-bottom: 1px solid #000;
}
.top>p{
text-align: center;
margin-top: 30px;
}
.bottom>p{
margin-top:10px;
}
</style>
js樣式
<script>
var input=document.querySelectorAll('input');
console.log(input);
(用戶名)
input[0].onfocus=function(){
this.nextElementSibling.innerHTML='支持中文磁滚、字母担映、數(shù)字的2-18個(gè)字符';
}
input[0].onblur=function(){
var reg=/^[\u4e00-\u9fa5a-zA-Z0-9]{2,18}$/;
var result=reg.test(input[0].value);
if(result==true){
this.nextElementSibling.innerHTML="通過";
}else{
this.nextElementSibling.innerHTML="格式錯(cuò)誤";
}
}
( 密碼)
input[1].onfocus=function(){
this.nextElementSibling.innerHTML='支持中文单匣、字母、數(shù)字的2-18個(gè)字符'
}
input[1].onblur=function(){
var reg=/^[\u4e00-\u9fa5a-zA-Z0-9]{2,18}$/;
var result=reg.test(input[1].value);
if(result==true){
this.nextElementSibling.innerHTML="通過";
}else{
this.nextElementSibling.innerHTML="格式錯(cuò)誤";
}
}
( 郵箱)
input[2].onfocus=function(){
this.nextElementSibling.innerHTML='支持123.165.qq等郵箱'
}
input[2].onblur=function(){
var reg=/^\w{3,11}@(123|165|qq).com$/;
var result=reg.test(input[2].value);
if(result==true){
this.nextElementSibling.innerHTML="通過";
}else{
this.nextElementSibling.innerHTML="格式錯(cuò)誤";
}
}
input[3].onfocus=function(){
this.nextElementSibling.innerHTML='請?jiān)俅屋斎肽拿艽a';
}
input[3].onblur=function(){
if(input[1].value==input[3].value){
this.nextElementSibling.innerHTML="通過";
}else{
this.nextElementSibling.innerHTML="不通過";
}
}
input[4].onfocus=function(){
this.nextElementSibling.innerHTML='請輸入您的手機(jī)號';
}
input[4].onblur=function(){
var ref=/^1[3456789]\d{9}$/;
var cer=ref.test(input[4].value);
if(cer){
this.nextElementSibling.innerHTML='通過';
}else{
this.nextElementSibling.innerHTML='請輸入正確格式的手機(jī)號';
this.nextElementSibling.nextElementSibling.innerHTML.display='none';
}
}
</script>
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者