验证邮箱地址唯一性
运行结果
![在这里插入图片描述](https://img-blog.csdnimg.cn/2021040120412833.gif)
案例步骤
1.获取文本框并为其添加离开焦点事件 2.离开焦点时,检测用户输入的邮箱地址是否符合规则 3.如果不符合规则,阻止程序向下执行并给出提示信息 4.向服务端发送请求,验证邮箱地址是否被别人注册过 5.根据服务器端返回值决定为客户端显示何种提示信息 6. 开启服务器,在浏览器地址栏中,输入localhost:3000/验证邮箱地址唯一性.html 7. 实现效果
HTML代码
邮箱地址:
CSS代码
*{
margin: 0;
padding: 0;
}
.container{
margin: 50px 100px;
}
.container #email{
outline: none;
text-indent: 2px;
}
// 邮箱输入正确
.bg-success{
background-color: rgba(0, 128, 100, 0.575);
}
// 邮箱输入错误
.bg-fail{
background-color: rgba(255, 51, 0, 0.863);
}
#info{
height: 40px;
margin-top: 40px;
line-height: 40px;
}
JS代码
将ajax.js文件引入到该页面中,发送请求时直接调用封装的ajax函数,函数代码传送门:ajax函数
|