如何使用javascript查找文件?

Mar*_*ner 5 html javascript iframe jquery

我的应用程序正在查看文件夹,然后在下拉菜单中显示其中的所有文件夹和html文件,并在iframe中显示任何html文件.我有一个名为"highlighted.html"的文件,我不想在下拉菜单中显示,但如果它在当前目录中,我想在iframe中自动显示它.

这是我的代码来显示文件夹中的内容:

  • 第一个函数创建一个下拉框,动态加载文件夹或文件(扩展名为html).

  • 在第二个函数中:如果单击现有的子文件夹,然后打开该文件夹并在里面查找html文件以在iframe中打开它

    function rendSelects($currentSelectItem, strPath) {
        var currentSelectLevel = (null === $currentSelectItem ? -1 : parseInt($currentSelectItem.attr('data-selector-level'))),
        nextOneSelectorHtml =
            '<select ' +
            'class="dropdown selectpicker" ' +
            'name="dd" ' +
            'data-selector-level="' + (currentSelectLevel + 1) + '" ' +
            'data-path="' + strPath + '" ' +
            'onchange="onFsSelectChange(this)"' +
            '><option text selected> -- select an option -- </option>';
    
        $('div.selectors-container select.dropdown').each(function (i, el) {
            if (parseInt(el.getAttribute('data-selector-level')) > currentSelectLevel) {
                el.parentNode.removeChild(el);
                $(el).selectpicker('destroy');
            }
        });
    
        if (fsStructure[strPath].subfolders.length > 0) {
            for (var i = 0; i < fsStructure[strPath].subfolders.length; i++) {
                nextOneSelectorHtml +=
                    '<option ' +
                    'class="subfolder-option" ' +
                    'data-subfolder="' + fsStructure[strPath].subfolders[i] + '" >' + fsStructure[strPath].subfolders[i] +
                '</option>';
            }
        }
    
        if (fsStructure[strPath].subshtmls.length > 0) {
            for (var i = 0; i < fsStructure[strPath].subshtmls.length; i++) {
                nextOneSelectorHtml +=
                    '<option ' +
                    'class="html-page-option" ' +
                    'data-html-page-name="' + fsStructure[strPath].subshtmls[i] + '">' + fsStructure[strPath].subshtmls[i] +
                    '</option>';
            }
        }
    
        nextOneSelectorHtml += '</select>';
        $('div.selectors-container').append(nextOneSelectorHtml);
        $('div.selectors-container').trigger('dropdownadded.mh');
    }
    
    function onFsSelectChange(el) {
        var currentSelectorPath = el.getAttribute('data-path'),
            selectedOption = el.options[el.selectedIndex];
    
        if (selectedOption.classList.contains('subfolder-option')) {
            loadFolderStructure(currentSelectorPath + '/' + selectedOption.getAttribute('data-subfolder'), $(el))
        }
    
        if (selectedOption.classList.contains('html-page-option')) {
            playSwf(currentSelectorPath + '/' + selectedOption.getAttribute('data-html-page-name'));
        }    
    }
    
    Run Code Online (Sandbox Code Playgroud)

我在http://tdhtestserver.herobo.com/上提供了一个工作演示.

解决了

Mar*_*ner 0

我回答我的问题是因为你们中的一些人还没有理解我的问题或者他们不知道该怎么做。所以我发现这很容易,我所做的只是一行代码。

high( currentSelectorPath + '/'+selectedOption.getAttribute('data-subfolder')+'/highlighted.html');
Run Code Online (Sandbox Code Playgroud)

这行改变了一切,high新的 iframe 在哪里

function onFsSelectChange( el ) {
  var 
    currentSelectorPath = el.getAttribute('data-path'),
    selectedOption = el.options[el.selectedIndex];

  if ( selectedOption.classList.contains('subfolder-option') ) {
    loadFolderStructure( currentSelectorPath + '/' + selectedOption.getAttribute('data-subfolder'), $(el) )
    high( currentSelectorPath + '/'+selectedOption.getAttribute('data-subfolder')+'/highlighted.html');
  } 
  if ( selectedOption.classList.contains('html-page-option') ) {
    playSwf( currentSelectorPath + '/' +  selectedOption.getAttribute('data-html-page-name') );
  }

}
Run Code Online (Sandbox Code Playgroud)