2016-12-01 79 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 
} 

}); 
});