我在 javascript 中搜索枚举用法。我在 JavaScript 中找到了一个 stackoverflow 链接 枚举?这是一个好的开始。
此链接显示了一个很好的用途,例如
var SIZE = {
SMALL : {value: 0, name: "Small", code: "S"},
MEDIUM: {value: 1, name: "Medium", code: "M"},
LARGE : {value: 2, name: "Large", code: "L"}
};
var currentSize = SIZE.MEDIUM;
if (currentSize == SIZE.MEDIUM) {
// this alerts: "1: Medium"
alert(currentSize.value + ": " + currentSize.name);
}
我的要求有点不同,这就是为什么我改变上面的代码
var MSg = {
Country= {
GBR: {name_req:"Name Required",email_req:"Email Required"},
FRA: {name_req:"FRA Name Required",email_req:"FRA Email Required"}
}
};
but it is giving error. so please guide me how to write the above code without error. also tell me the enum code will work in all the browser? thanks.
供我自己将来参考
var dialog =
{
MainContainer:
{
Country:
{
GBR:
{
height: 365, width: 257
},
FRA:
{
height: 375, width: 310
}
}
},
SubContainer:
{
Country:
{
GBR:
{
height: 0, width: 257
},
FRA:
{
height: 0, width: 300
}
}
}
};
var Validation =
{
Msg:
{
Country:
{
GBR:
{
Name: "Name Required",
Subject: "Subject Required",
Email: "Email Required",
Invalid_Email: "Invalid Email Address",
Feedback: "Feedback details Required",
Success: "Feedback send successfully",
Fail: "Feedback send fail"
},
USA:
{
Name: "Name Required",
Subject: "Subject Required",
Email: "Email Required",
Invalid_Email: "Invalid Email Address",
Feedback: "Feedback details Required",
Success: "Feedback send successfully",
Fail: "Feedback send fail"
}
}
}
};
分配或设置国家
var feedCookie = getCookie('SetCountry');
feedCookie = (feedCookie == '' ? 'GBR' : feedCookie);
var dialog_Main = dialog.MainContainer.Country[feedCookie];
var dialog_Sub = dialog.SubContainer.Country[feedCookie];