jquery判断两次密码不一致

jquery检测输入密码两次不一样提示

输入密码: <input type="password" name="password1" id="password1"/>
确认密码: <input type="password" name="password2" id="password2" onkeyup="validate()"/>
<span id="tishi"></span>
<input type="submit" value="注册" id="submit"/>

 

js部分

function validate() {
var password1 = document.getElementById("password1").value;
var password2 = document.getElementById("password2").value;
if(password1 == password2) {
document.getElementById("tishi").innerHTML="<font color='green'>两次密码相同</font>";
document.getElementById("submit").disabled = false;
}
else {
document.getElementById("tishi").innerHTML="<font color='red'>两次密码不相同</font>";
document.getElementById("submit").disabled = true;
}
}

posted @ 2017-08-15 15:00  瞎BB的是2B  阅读(1843)  评论(0编辑  收藏  举报