如何根据 Javascript 中的变量设置属性值
问题是我有这段代码(Jquery UI):
$("#dialog-confirm").dialog({
resizable: false,
modal: true,
buttons: {
"Remove": function() {
$(this).dialog("close");
},
"Cancel": function() {
$(this).dialog("close");
}
}
});
现在我必须通过为每个按钮提供单词翻译来将其国际化。我对变量 STR_REMOVE 和 STR_CANCEL 进行了翻译,但如果我执行类似
buttons: {
STR_REMOVE: function() {
$(this).dialog("close");
},
STR_CANCEL: function() {
$(this).dialog("close");
}
}
按钮(属性)的操作,则采用值“STR_REMOVE”和“STR_CANCEL”,而不是其内容。那么,问题是,我能做什么?
The problem is I have this piece of code (Jquery UI):
$("#dialog-confirm").dialog({
resizable: false,
modal: true,
buttons: {
"Remove": function() {
$(this).dialog("close");
},
"Cancel": function() {
$(this).dialog("close");
}
}
});
and now I have to internationalize it by giving to each button a word translation. I have the translation on the variables STR_REMOVE and STR_CANCEL, but if I do something like
buttons: {
STR_REMOVE: function() {
$(this).dialog("close");
},
STR_CANCEL: function() {
$(this).dialog("close");
}
}
the buttons (the properties) take the value "STR_REMOVE" and "STR_CANCEL", not its content. So, the question is, what can I do?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
试试这个。
看看 jquery ui 文档: http://jqueryui.com/demos/dialog/#选项按钮
Try this.
have a look at the jquery ui doc: http://jqueryui.com/demos/dialog/#option-buttons
您不能内联执行此操作。您必须首先声明对象,然后使用方括号成员运算符 设置属性:
You can't do this inline. You'll have to declare the object first, then use the square bracket member operator to set the properties:
试试这个,未测试:
Try this, not tested: