2016-12-01 51 views
-4

你可以在jshint上看到什么。 .prop registerUserButton似乎有问题。我简单的jquery脚本有什么问题?

$(document).ready(function() { 
    console.log("ready"); 
    $('#registerUserButton').prop("disabled", true); 

    $('#reg_passwordConfirm').bind('keyup', function() { 
    var Password = $("#reg_password"); 
    var confirmPassword = $("#reg_passwordConfirm"); 

    if ((Password == confirmPassword) && (Password > 1) && (confirmPassword == 1)) { 
     $('#registerUserButton').prop("disabled", false); 
    } 
    }); 
}); 
+1

什么是错在哪里?它不起作用吗?任何错误? – empiric

+1

将您的代码复制到[jshint](http://jshint.com/)不会泄露任何东西 – empiric

+0

Password> 1'应该做什么?我假设你的密码不是“整数” – empiric

回答

1
var Password = $("#reg_password"); 
var confirmPassword = $("#reg_passwordConfirm"); 

应该

var Password = $("#reg_password").val(); 
var confirmPassword = $("#reg_passwordConfirm").val(); 
1
var Password = $("#reg_password").val(); 
var confirmPassword = $("#reg_passwordConfirm").val(); 
(Password.length > 1) && (confirmPassword.length == 1) 

,也许解决您的问题

0

您好首先你作出形式上值的调理一些错误,我编辑的脚本一点点+修正错误并添加评论

$(document).ready(function() { 


console.log("ready"); 
    $('#registerUserButton').prop("disabled", true); 

    $('#reg_passwordConfirm').bind('keyup', function() { 
    var Password = $("#reg_password").val(); // you have to add the .val() 
    var confirmPassword = $("#reg_passwordConfirm").val(); // you have to add the .val() 

if ((Password == confirmPassword) && (Password > 1) && (confirmPassword === 1)) { 
    $('#registerUserButton').prop("disabled", false); 
}else { //error handling for the password 
var errMsg = "Sorry but the passwords doesnt match."; 
$('#registerUserButton').append(errMsg); 
$('#registerUserButton').prop("disabled", true); //Making sure button is disabled 
} 

}); 
});