实现鼠标移开输入框,即刻提示输入内容是否可用
用户名唯一效验
输入框
<p id="p"></p>
<input type="text" name="userName" id="userName">
js
<script>
userName.onblur = function () {
$.post(
"/admin/isname" ,
{ username: userName.value,aeg:18},
function (data) {
if (data.code=="400"){
$("#p1").html("用户名已被注册,请重新输入!").css("color","red");
}else {
$("#p1").html("用户名可用!").css("color","green");
}
});
};
</script>
两次输入密码一致性效验
输入框
<b id="warning" style="color: red"></b>
<input type="password" name="user.password" id="password">
<input type="password" name="repeatPassword" id="repeatPassword" onblur="check()">
js
<script>
function check(){
if(
document.getElementById("password").value!= document.getElementById("repeatPassword").value
) {
document.getElementById("warning").innerHTML=" 两次密码的输入不一致";
}else{
document.getElementById("warning").innerHTML=" ";
}
};
</script>
用户名唯一性校验和密码一致性校验的实现方式可通用。