我在这个问题中提出了一个问题Stackoverflow,它的工作原理是完美的。对所有给我答复的用户都是如此。但是现在我还有其他问题。加载Javascript对象文件
我想要在一个单独的文件中的对象,所以我只需要更新该文件而不是JS文件(否则它会很大)。我正在使用JQUERY。
我现在看起来像这样(所有的信息在JS文件中)。 IBANInfo被用于填充选择框
var IBANInfo = {
"ccAL":{
countryCode:"AL",
countryName:"Albanië",
IBANlength:"28",
bankFormCode:"0 8n 0 ",
accountNum:"0 16 0 "
},
"ccAD":{
countryCode:"AD",
countryName:"Andorra",
IBANlength:"24",
bankFormCode:"0 4n 4n",
accountNum:"0 12 0 "
},
"ccBE":{
countryCode:"BE",
countryName:"België",
IBANlength:"16",
bankFormCode:"0 3n 0 ",
accountNum:"0 7n 2n"
}
};
//---- then this function is used to build the selectList
function createSelect(){
var selectList = '';
var key;
selectList += "<option value=''>Kies een land</option>\n";
for (key in IBANInfo) {
if (IBANInfo.hasOwnProperty(key)) {
var countryInfo = IBANInfo[key];
selectList += "<option value='"+countryInfo.countryCode+"'>"+countryInfo.countryName+"</option>\n";
}
}
$('#selectBox').html(selectList);
}
我想我能做到这样,但我得到了我的选择框未定义的消息。
var IBANInfo = $.get('include/countryCodes.txt');
// also tried var IBANInfo = $.getJSON('include/countryCodes.txt');
//---- then this function is used to build the selectList
function createSelect(){
var selectList = '';
var key;
selectList += "<option value=''>Kies een land</option>\n";
for (key in IBANInfo) {
if (IBANInfo.hasOwnProperty(key)) {
var countryInfo = IBANInfo[key];
selectList += "<option value='"+countryInfo.countryCode+"'>"+countryInfo.countryName+"</option>\n";
}
}
$('#selectBox').html(selectList);
}
/*
the countryCodes.txt file is like this:
{
"ccAL":{
countryCode:"AL",
countryName:"Albanië",
IBANlength:"28",
bankFormCode:"0 8n 0 ",
accountNum:"0 16 0 "
},
"ccAD":{
countryCode:"AD",
countryName:"Andorra",
IBANlength:"24",
bankFormCode:"0 4n 4n",
accountNum:"0 12 0 "
},
"ccBE":{
countryCode:"BE",
countryName:"België",
IBANlength:"16",
bankFormCode:"0 3n 0 ",
accountNum:"0 7n 2n"
}
}
*/
我在做什么错。 TNX提前
额外的信息: 我已经犯了一个网站来产生IBANnumbers,你可以找到它的iban.wswebcreation.nl。在这个网站上你可以生成1-100个IBAN号码。我想做的是一种验证用户想要验证的IBAN号码的方法。他可以通过在输入字段中填写IBANnumber来完成此操作(请参阅其他站点)。
如果你看到源文件,你会看到var IBANInfo在JS文件中。我想把它放在一个加载的单独的txt文件中。 IBANInfo包含使用IBANnumber的国家的所有信息(数字的数量,国家代码,帐户编号的构建方式等)。 我现在用一些帮助作为对象,看到前面问题的链接。这工作。但在将来我也想用IBANInfo来验证IBAN号码。
希望你现在有足够的信息
如果您接受其他问题的一些答案,人们会更倾向于帮助您。 – 2010-04-05 07:47:26
我如何接受答案?我是否需要回答我得到它的问题? – Megapool020 2010-04-05 08:04:51
单击答案的投票计数下的复选标记。 – prodigitalson 2010-04-05 08:07:45