【发布时间】:2015-03-13 20:18:05
【问题描述】:
我正在尝试制作密码检查系统。 我决定还要检查它是否是常用密码。
为此,我将一个外部 txt 文件加载到一个数组中。但是,我的密码检查功能似乎无法读取此数组。
jQuery(document).ready(function() {
var commonPass = new Array;
jQuery.get('/static/commonPass.txt', function(data){
commonPass = data.split('\n');
console.log(commonPass);
});
console.log(commonPass);
//you have to use keyup, because keydown will not catch the currently entered value
jQuery('input[type=password]').keyup(function() {
// set password variable
var pswd = jQuery(this).val();
//check if common password
console.log(pswd);
if ( jQuery.inArray(str.toLowerCase(pswd), commonPass)!= -1) {
console.log('InArray');
jQuery('#known').removeClass('valid').addClass('invalid');
} else {
console.log('NotInArray');
jQuery('#known').removeClass('invalid').addClass('valid');
}
});
是否可以创建全局 jQuery/Javascript 变量,这是否可以解决这个问题?
【问题讨论】:
-
当您尝试理解数组时遇到什么错误?
-
数组只是空的
-
KJ Prince 已经回答了。这是工作。它加载得很好,只是无法弄清楚如何在加载函数范围之外访问 var。
标签: javascript jquery arrays passwords