javascript实现密码验证

javascript实现密码验证

javascript密码验证代码如下

<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>密码验证</title> <script src="https://www.jb51.net/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="输入密码"> <label></label> </label> <br><br> <label> 验证密码:<input type="text" placeholder="输入相同密码"> <label></label> </label> <br><br> <button>submit</button> </div> </body> </html>

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wgzxfw.html