0

我的目标:我需要使用 fso - activeX 读取 txt 文件,然后用 ; 分隔文本 并将每个分隔的单词放在 select - 选项中。到目前为止,我得到了这个,但没有工作

<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>
4

1 回答 1

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);
    }
}

我的代码现在可以工作了,看起来像这样

于 2013-08-19T06:26:53.483 回答