Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/73.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 用于文件选择的动态下拉列表_Javascript_Html - Fatal编程技术网

Javascript 用于文件选择的动态下拉列表

Javascript 用于文件选择的动态下拉列表,javascript,html,Javascript,Html,我正在尝试调整现有的.html文件以添加功能。我对前端开发环境非常陌生 <form action="javascript:void(0);"> <input type="button" name="Load" value="Load" onclick="fileLoad();"/> <input type="button" name="showFiles" value="Select File" onclick="selectFiles();"/&g

我正在尝试调整现有的.html文件以添加功能。我对前端开发环境非常陌生

<form action="javascript:void(0);">
    <input type="button" name="Load" value="Load" onclick="fileLoad();"/>
    <input type="button" name="showFiles" value="Select File" onclick="selectFiles();"/>
</form>


我想有一个下拉列表(动态列表)。当我单击按钮“选择文件”时会发生这种情况。我尝试使用
selectFiles()
函数来实现这一点。尽管如此,我可以从后端获取文件列表。从服务器获取列表后,如何在前端显示该列表

function makeList(fileNames) {
    // create a container for the select in your html
    var myDiv = document.getElementById("myDiv");  
    // Create and append select list
    var selectList = document.createElement("select");
    selectList.id = "filesSelect";
    myDiv.appendChild(selectList);

    // Create and append the options
    for (var i = 0; i < fileNames.length; i++) {
        var option = document.createElement("option");
        option.value = fileNames[i]; // this will depend on the datastructure of your list items
        option.text = fileNames[i]; // this will depend on the datastructure of your list items
        selectList.appendChild(option);
    }
}
函数生成列表(文件名){
//在html中为select创建一个容器
var myDiv=document.getElementById(“myDiv”);
//创建并附加选择列表
var selectList=document.createElement(“选择”);
selectList.id=“fileselect”;
myDiv.appendChild(选择列表);
//创建并附加选项
对于(var i=0;i
此函数应作为对服务器调用的回调

我还没有测试过它,但它应该会给你一个清晰的想法