分类分类
更新时间:2026-11-27 01:44:00作者:fang
本文为大家分享了javascript密码验证的实现方法,欢迎大家阅读。

![]()
javascript密码验证代码如下
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>密码验证</title>
<script src="js/jquery-1.11.1.js"></script>
<script>
$(function(){
$(document).on('blur','input',function(){
var $password=$('#password').val();
var $password_again=$('#password_again').val();
if(!$password){
$("#password").addClass('redBorder').next('label').show().html('不能为空');;
return false;
}else if(!$password_again){
$("#password_again").addClass('redBorder').next('label').show().html('不能为空');
return false;
}else{
$('input').removeClass('redBorder').next('label').empty();
if($password_again==$password){
$("#password,#password_again").next('label').show().html('两次密码一致').addClass('valid');
}else if($password_again!=$password){
$("#password,#password_again").addClass('redBorder').next('label').show().html('两次密码不一致').removeClass('valid').addClass('erro');
}
}
})
})
</script>
<style>
.redBorder{
border: 1px solid red;
}
.erro{
background: url('images/unchecked.gif') no-repeat;
padding-left: 16px;
}
.valid{
background: url('images/checked.gif') no-repeat;
width: 16px;
height: 16px;
}
</style>
</head>
<body>
<div>
<label>
输入密码:<input type="text" placeholder="输入密码" id="password">
<label id="password-erro" class="erro" style="display:none;"></label>
</label>
<br><br>
<label>
验证密码:<input type="text" placeholder="输入相同密码" id="password_again">
<label id="password-erro" class="erro" style="display:none;"></label>
</label>
<br><br>
<button style="margin-left:80px;">submit</button>
</div>
</body>
</html>
希望本文对大家学习javascript程序设计有所帮助。
相关
轻听英语学习办公88.4 MBv2.7.212026-11-26
下载喵喵王国角色扮演1.15Gv00.40.012026-11-26
下载pokecatch游戏休闲益智410Kv1.02026-11-26
下载摇曳露营拼图露营休闲益智82.14 Mv1.7.52026-11-26
下载暗金秘录角色扮演316.84 Mv0.365.02026-11-26
下载AI剪辑图像拍照196.82 MBv21.52026-11-25
下载精灵联萌0.05折版策略游戏13.63 Mv1.0.02026-11-25
下载MilkSU内核管理器实用工具14.29 Mv0.2.62026-11-25
下载百炼仙途角色扮演528.9 Mv10002026-11-25
下载蛊界永生角色扮演407.01 Mv0.4.162026-11-25
下载幻梦无年动作射击276.68 Mv1.1.02026-11-25
下载假人慢打漂泊带土动作射击856.96 Mv0.9.02026-11-25
下载










