我有這樣的Java腳本代碼:的Javascript循環通過一個對象來填充HTML選擇
var LANGS = {
"C#": [10, "text/x-csharp"],
"C/C++": [7, "text/x-c++src"],
"Clojure": [2, "text/x-clojure"],
"Java": [8, "text/x-java"],
"Go": [6, "text/x-go"],
"Plain JavaScript": [4, "text/javascript"],
"PHP": [3, "text/x-php"],
"Python": [0, "text/x-python"],
"Ruby": [1, "text/x-ruby"],
"Scala": [5, "text/x-scala"],
"VB.NET": [9, "text/x-vb"],
"Bash": [11, "text/x-bash"],
"Objective-C": [12,"text/x-objectivec"],
"MySQL": [13,"text/x-sql"],
"Perl": [14, "text/x-perl"],
}
我現在我有下面的代碼表明,信息警報:
$('#langhelp').on('click', function() {
var msg = "These are the languages and their langids: \n[LANGID]: [LANGUAGE]\n";
var langs = [];
for (var i in LANGS) {
msg += LANGS[i][0] + ": " + i + "\n";
}
alert(msg);
});
但我想要做的是用這個數據填充一個HTML選擇,但我不知道如何去做,我已經看過這個question,但沒有看到如何將選項附加到select元素。
您希望在什麼時候填充選擇框? – dfsq
只是在頁面加載。 –
什麼應該是標籤和選項的值,將使用'text/x-csharp'? – dfsq