变量jquery参数名称

时间:2013-04-25 16:57:24

标签: javascript jquery

我有一组PHP语言文件,用于根据用户的语言选择向用户输出文本。我已成功将PHP变量传递给javascript,它们以LANG形式提供。您可以在代码中看到它正在使用中。

这是我的问题...由于下面显示的代码完美无缺,为什么我不能改变这一行......

'No': { 'class' : ''}}

LANG.no: { 'class'  : ''}}

基本上我想知道为什么我可以在代码中的其他地方使用LANG,但不能在上面显示的行或等效的“是”行中使用。{/ p>

以下是工作代码:

$.confirm({
    'title': LANG.return_to_exhibit_lobby,
'message': "<strong>"+LANG.return_to_exhibit_lobby_confirmation+"</strong>",
'buttons': {
'Yes': { 
    'class': 'special',
    'action': function(){
        window.location.href='logout.php';
    }},
'No': { 'class' : ''}}
});

2 个答案:

答案 0 :(得分:4)

你能做什么呢?

var params = {
    'title': LANG.return_to_exhibit_lobby,
    'message': "<strong>"+LANG.return_to_exhibit_lobby_confirmation+"</strong>",
    'buttons': {
        'Yes': { 
            'class': 'special',
            'action': function(){
                window.location.href='logout.php';
             }}
};

params.buttons[LANG.No] = { 'class' : ''};

$.confirm(params);

答案 1 :(得分:4)

那是因为你在对象文字中。语法规则不同,因为您声明了一个结构,而不是对它进行操作。你可以这样做:

var data = {
    'title': LANG.return_to_exhibit_lobby,
    'message': "<strong>"+LANG.return_to_exhibit_lobby_confirmation+"</strong>",
    'buttons': {}
};
data.buttons[Lang.No] = { 'class' : ''}
$.confirm( data );