我有這樣的代碼財產「密碼強度」,並獲得在第一行JavaScript錯誤:無法設置的不確定
錯誤是「無法設置屬性‘密碼強度’的未定義」
代碼:
window.myProject.passwordStrength = function ($, window, document) {
var desc = new Array();
desc[0] = "Very Weak";
desc[1] = "Weak";
desc[2] = "Better";
desc[3] = "Medium";
desc[4] = "Strong";
desc[5] = "Very Strong";
return {
maxScore: 5,
allowedScore: 4,
getStrengthDescription: function(score){
return desc[score];
},
getStrength: function(password){
var score = 0;
//if password bigger than 6 give 1 point
if (password.length > 6) score++;
//if password has both lower and uppercase characters give 1 point
if ((password.match(/[a-z]/)) && (password.match(/[A-Z]/))) score++;
//if password has at least one number give 1 point
if (password.match(/\d+/)) score++;
//if password has at least one special caracther give 1 point
if (password.match(/.[!,@,#,$,%,^,&,*,?,_,~,-,(,)]/)) score++;
//if password bigger than 12 give an other 1 point
if (password.length > 12) score++;
return score;
}
};
}(jQuery, window, document);
我在我的頁面調用此爲:
<script>
$(function() {
$(document).ready(function() {
var passwordStrength = window.myProject.passwordStrength();
$('#Password').keyup(function() {
var strength = passwordStrength.getStrength($(this).val());
}
</script>
是什麼'window.myProject'? – Krishna
究竟是什麼問題? –
錯誤消息應該是不言自明的。 'window.myProject'是未定義的(即它不存在)。 – JJJ