2013-08-16 28 views
0

我的目標:我需要閱讀txt文件使用FSO - 的ActiveX然後單獨的文本;並將每個分隔的單詞放在select - 選項中。 到目前爲止,我得到了這一點,但AINT工作使用ActiveX單獨讀取文件;並放在選擇 - 選項

<script> 
    function readAll() { 
     var fso = new AcitveXObject("Scripting.FileSystemObject"); 
     var txtFile = fso.OpenTextFile("kategorije.txt", 1, false, 0); 
     var fText = txtFile.ReadAll(); 
     txtFile.Close(); 
    } 

    var array = fText.split(";"); 
    var sel = document.getElementById("dropdown2"); 
    for (var i = 0; i < dropdown2.length; i++) { 
     var opt = document.createElement("option"); 
     opt.innerHTML = fText[i]; 
     opt.value = fText[i]; 
     sel.appendChild[opt]; 
    } 
</script> 

回答

1
function readAll() { 
    var fso = new ActiveXObject("Scripting.FileSystemObject"); 
    var txtFile = fso.OpenTextFile("kategorije.txt", 1, false, 0); 

    var fText = txtFile.ReadAll(); 
    txtFile.Close(); 
    fso = null 
    var array = fText.split("\r\n"); 
    var sel = document.getElementById("dropdown2"); 
    for (var i = 0; i < array.length; i++) { 
     var opt = document.createElement("option"); 
     opt.innerHTML = array[i]; 
     opt.value = array[i]; 
     sel.appendChild(opt); 
    } 
} 

我的代碼工作,現在,它看起來像這樣

相關問題