好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

简单的密码强度插件_html/css_WEB-ITnose

之前做的通行证项目,里面的注册模块中输入密码需要显示密码强度(低中高)。当然这只是一个很简单的密码强度显示功能,不像网上那么复杂,能够满足一般的需求。

function PasswordStrength(passwordID,strengthID){    var _this = this;    _this.init(strengthID);    document.getElementById(passwordID).onkeyup = function(){        _this.checkStrength(this.value);    }}PasswordStrength.prototype.init = function(strengthID){    var id = document.getElementById(strengthID);    var div = document.createElement('div');    var strong = document.createElement('strong');    this.oStrength = id.appendChild(div);    this.oStrengthTxt = id.parentNode.appendChild(strong);}PasswordStrength.prototype.checkStrength = function (val){    var aLvTxt = ['','低','中','高'];    var lv = 0;    if(val.match(/[a-z]/g)){lv++;}    if(val.match(/[0-9]/g)){lv++;}    if(val.match(/(.[^a-z0-9])/g)){lv++;}    if(val.length   3){lv=3;}    this.oStrength.className = 'strengthLv' + lv;    this.oStrengthTxt.innerHTML = aLvTxt[lv];} 

参数说明

对象的第一个参数是密码输入框的 id,第二个参数是密码强度长条的 id; checkStrength方法中可以自定义密码强度的规则; 密码强度显示低中高分别对应 3 个 css 样式(strengthLv1、strengthLv2、strengthLv3)。

如何使用

             密码强度       #passStrength{height:6px;width:120px;border:1px solid #ccc;padding:2px;} .strengthLv1{background:red;height:6px;width:40px;} .strengthLv2{background:orange;height:6px;width:80px;} .strengthLv3{background:green;height:6px;width:120px;}             

密码强度:

查看更多关于简单的密码强度插件_html/css_WEB-ITnose的详细内容...

  阅读:35次