【发布时间】:2010-04-05 07:43:36
【问题描述】:
我在此线程Stackoverflow 中提出了一个问题,它运行良好。所以tnx给所有给我回复的用户。但现在我还有一个问题。
我想将对象放在一个单独的文件中,所以我只需要更新文件而不是 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"
}
}
*/
我做错了什么。提前通知
额外信息: 我已经创建了一个网站来生成 IBAN 号码,你可以在 iban.wswebcreation.nl 上找到它。在此站点上,您可以生成 1-100 个 IBAN 号码。我想做的是一种验证用户想要验证的 IBAN 号码的方法。他可以通过在输入字段中填写 IBAN 号码来做到这一点(请参阅其他网站)。
如果您查看源文件,您将看到 var IBANInfo 在 JS 文件中。我想把它放在一个单独的 txt 文件中。 IBANInfo 包含使用 IBANnumber 的国家/地区的所有信息(位数、国家代码、帐号的构建方式等)。 我现在作为一个对象在一些帮助下完成了它,请参阅前一个问题的链接。这行得通。但将来我还想使用 IBANInfo 来验证 IBAN 号码。
希望你现在有足够的信息
【问题讨论】:
-
如果您接受其他问题的部分答案,人们会更愿意帮助您。
-
我如何接受答案?我需要回答我让它工作的问题吗?
-
点击投票数下方的复选标记。
-
回答了所有问题,我太傻了。希望现在有人能帮助我,因为我总是使用答案并尝试它们
-
旁注:假设您使用的是 Unicode(很少有不使用的理由),例如UTF-8 编码,您不需要将 ë 编码为
&euml;- 任何字符都可以在 Unicode 中按原样表示。