[英]Validation error besides textbox
I have validation error display besides text box. 除了文本框,我还有验证错误显示。 The value -1, shows error, while the value 0 show alert that the password is correct.
值-1表示错误,而值0表示警告密码正确。 The first time user input incorrect password, it display the validation error.
用户首次输入不正确的密码时,将显示验证错误。
However, the second time it have wrong input, the validation error does not show. 但是,第二次输入错误时,不会显示验证错误。 I console log the value, it still show the error value(-1) but the validation message doesn't show up.
我在控制台上记录了该值,它仍然显示错误值(-1),但未显示验证消息。 I couldn't see what's wrong with my code.
我看不到代码有什么问题。
I'm using if else statement. 我正在使用if else语句。 Does anyone expert could pointed out what might be the cause of this?
有谁能指出这可能是什么原因?
var clearFields = function() {
$('#current_pwd').val('');
$('#new_pwd').val('');
$('#retype_pwd').val('');
$('#current_label').html('');
$('#new_label').html('');
$('#retype_label').html('');
$('#current_label').prop('hidden',true);
$('#new_label').prop('hidden',true);
$('#retype_label').prop('hidden',true);
}
var changePassword = function () {
var $result = {};
$.ajax({
url: "users/resetpwd",
type: "POST",
async: false,
data: $("#changePasswordID").serialize(),
success: function(result) {
$result = $.parseJSON(result);
}
});
console.log($result["ret"]);
if($result["ret"] == -1) {
$result["ret"] == -1;
$('#current_label').html($result["curr_msg"]);
$('#new_label').html($result["new_msg"]);
$('#retype_label').html($result["ret_msg"]);
$('#current_label').prop('hidden',false);
$('#new_label').prop('hidden',false);
$('#retype_label').prop('hidden',false);
alert('Password does not match.');
} else if($result["ret"] == 0) {
$('#current_label').prop('hidden',true);
$('#new_label').prop('hidden',true);
$('#retype_label').prop('hidden',true);
alert('Password Changed.');
clearFields();
};
};
reset the counter to its default value at the start of your validation. 在验证开始时将计数器重置为其默认值。 Then as the validation runs, it will change the counter -1 or 0 depending on the user input.
然后,在运行验证时,它将根据用户输入更改计数器-1或0。 See if that works.
看看是否可行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.