表单案例
2018-07-20 本文已影响0人
LzW伟
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>
请确认密码:<input type="password" placeholder="请输入密码">
<span></span>
</p>
<p>
请输入手机号:<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='支持中文、字母、数字的2-18个字符';
}
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="格式错误";
}
}
( 密码)
input[1].onfocus=function(){
this.nextElementSibling.innerHTML='支持中文、字母、数字的2-18个字符'
}
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="格式错误";
}
}
( 邮箱)
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="格式错误";
}
}
input[3].onfocus=function(){
this.nextElementSibling.innerHTML='请再次输入您的密码';
}
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='请输入您的手机号';
}
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='请输入正确格式的手机号';
this.nextElementSibling.nextElementSibling.innerHTML.display='none';
}
}
</script>