修改密码formValidator and 眼睛切换

日期:2019-03-19 浏览:193次

/*style*/
#editUserMsg .fv-form-bootstrap .form-control-feedback {
right: 40px;
}
<!–修改用户资料–>
<div class=”modal fade modal-primary formModal” id=”editUserMsg” aria-hidden=”true” aria-labelledby=”editUserMsg” role=”dialog” tabindex=”-1″>
<div class=”modal-dialog modal-center”>
<div class=”modal-content”>
<div class=”modal-header”>
<button type=”button” class=”close” data-dismiss=”modal” aria-label=”关闭”>
<span aria-hidden=”true”>×</span>
</button>
<h4 class=”modal-title”>修改密码</h4>
</div>
<form id=”postForm” method=”post” class=”modalForm”>
<div class=”modal-body clearfix”>
<div class=”form-group”>
<div class=”input-group”>
<span class=”input-group-addon”><i class=”icon wb-user”></i></span>
<input type=”text” class=”form-control” placeholder=”手机号码” value=”{$info.username ?? ”}” readonly name=”username” >
</div>
</div>
<div class=”form-group”>
<div class=”input-group”>
<span class=”input-group-addon”><i class=”icon wb-lock”></i></span>
<input type=”password” class=”form-control” placeholder=”旧密码” name=”password” >
<span class=”input-group-addon” onclick=”passwordEdit(this)”><i class=”fa fa-eye-slash”></i></span>
</div>
</div>
<div class=”form-group”>
<div class=”input-group”>
<span class=”input-group-addon”><i class=”icon wb-lock”></i></span>
<input type=”password” class=”form-control” placeholder=”新密码” name=”repassword” >
<span class=”input-group-addon” onclick=”passwordEdit(this)”><i class=”fa fa-eye-slash”></i></span>
</div>
</div>
</div>
<div class=”modal-footer”>
<button type=”submit” class=”btn btn-primary”>保存</button>
<button type=”button” class=”btn btn-default” data-dismiss=”modal”>取消</button>
<input type=”hidden” name=”id” value=”{$info.id ?? ”}”>
</div>
</form>
</div>
</div>
</div>
// 修改用户资料
function formValidator() {
$(‘#postForm’).formValidation({
excluded:[“:disabled”,”:not(:visible)”],
err: {
container: ‘tooltip’
},
icon: {
valid: ‘icon wb-check’,
invalid: ‘icon wb-close’,
validating: ‘icon wb-refresh’
},
fields: {
username: {
validators: {
notEmpty: { message: ‘手机号码不能为空’ },
regexp: { regexp: /^1[1-9][0-9]\d{8}$/, message: ‘手机号码无效’ }
}
},
password: {
validators: {
notEmpty: { message: ‘密码不能为空’ },
stringLength: { min: 4, max: 16, message: ‘4-16个字符’},
regexp:{ regexp:/^[\w-]+$/, message: ‘字母、数字、下划线、破折号’}
}
},
repassword: {
validators: {
notEmpty: { message: ‘密码不能为空’ },
stringLength: { min: 4, max: 16, message: ‘4-16个字符’},
regexp:{ regexp:/^[\w-]+$/, message: ‘字母、数字、下划线、破折号’}
}
},
}
}).on(‘success.form.fv’, function(e) {
e.preventDefault();
var $form = $(e.target);
$.ajax({
type:”POST”,
url: “{:\\think\\Url::build(‘user’)}”,
dataType:”json”,
data:$form.serialize(),
beforeSend:function(){
$form.find(‘button[type=”submit”]’).text(‘保存中…’).attr(‘disabled’,true);
},
success: function (res) {
$form.find(‘button[type=”submit”]’).text(‘保存’).attr(‘disabled’,false);
if( res.code == 0){
$(‘#editUserMsg’).modal(‘hide’);
toastr.success(res.msg, “温馨提示”);
}
else{ toastr.error(res.msg, “温馨提示”);}
},
error:function () {
toastr.error(‘请联系管理人员’, “温馨提示”);
}
});
});
}

//输入密码眼睛
function passwordEdit(obj) {
var thisObj=$(obj);
var thisClass = thisObj.children().attr(“class”)
if (thisClass == ‘fa fa-eye’) {
thisObj.children().removeClass(‘fa-eye’).addClass(‘fa-eye-slash’)
thisObj.siblings(‘input’).attr(‘type’,’password’);
}else {
thisObj.children().removeClass(‘fa-eye-slash’).addClass(‘fa-eye’)
thisObj.siblings(‘input’).attr(‘type’,’text’);
}
}

没有评论

发表评论