本文介紹了來自變量的 jQuery UI 對話框按鈕的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
我有變量保存 jquery ui 對話框中按鈕的翻譯標簽.
I have variables holding the translated labels for buttons inside a jquery ui dialog.
我無法用變量本身填充按鈕數組鍵,也找不到任何方法讓它將我的變量視為字符串.
I cannot fill the button array key with the variable itself, and can't find any way to let it treat my variable just as string.
translations['ok'] = 'ok';
translatinos['cancel'] = 'cancel';
// not working
jQuery('#foo').dialog({
buttons:
{
translations['ok']: function() { alert('foo-ok'); },
translations['cancel']: function() { alert('foo-cancel'); }
}
});
// working
jQuery('#bar').dialog({
buttons:
{
"Ok": function() { alert('bar-ok'); },
"Cancel": function() { alert('bar-cancel'); }
}
});
有沒有辦法讓它與可變數組鍵一起工作?
Is there any way to get this to work with variable array keys?
推薦答案
你可以試試這個,可能有幫助:
You can try this, may be it helps:
var buttonsOpts = {}
buttonsOpts[translations["ok"]] = function ....
buttonsOpts[translations["cancel"]] = function ....
jQuery('#bar').dialog({
buttons : buttonsOpts
});
希望對你有幫助!
這篇關于來自變量的 jQuery UI 對話框按鈕的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!