如何用JavaScript找到一个文件?

编程入门 行业动态 更新时间:2024-10-06 18:32:57
本文介绍了如何用JavaScript找到一个文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

这是我的代码,用于显示文件夹中的内容:

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

  • 第二个功能:如果点击一个现有的子文件夹,然后打开该文件夹并查看html文件( s)在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 ='+ strP '+'b $ b'onchange =onFsSelectChange(this)''+ '><选择文本选择> - 选择一个选项 - < / option>'; $ b $('div.selectors-container select.dropdown')。each(function(i,el){ if(parseInt(el.getAttribute('data-selector-level' ))> currentSelectLevel){ el.parentNode.removeChild(el); $(el).selectpicker('destroy'); } }); (fsStructure [strPath] .subfolders.length> 0){ for(var i = 0; i< fsStructure [strPath] .subfolders.length; i ++){ b $ b nextOneSelectorHtml + = '< option'+ 'class =subfolder-option'+ 'data-subfolder =''+ fsStructure [strPath] .subfolders [i ] +''>'+ fsStructure [strPath] .subfolders [i] + '< / option>'; (fsStructure [strPath] .subshtmls.length> 0){ for(var i = 0; i< fsStructure [strPath; } } if ] .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'); } 函数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('数据HTML页名')); code $ $ b $ p

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

    已解决

    解决方案

    你没有理解我的问题,或者他们不知道如何去做。所以我发现这很简单,我所做的只有一行代码。

    high(currentSelectorPath +'/ '+ selectedOption.getAttribute(' 数据子文件夹 ')+'/ highlighted.html');

    这条线改变了一切,其中 high 是一个新的iframe

    函数onFsSelectChange(el){ var currentSelectorPath = el.getAttribute('数据路径'), 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-名称') ); } }

    My app is looking into a folder and then show all folders and html file inside it in a dropdown menu, and display any html files inside an iframe. I have a file called "highlighted.html" which I don't want to show in the dropdown menu, but if it is in the current directory I do want to show it automatically in an iframe.

    This is my code to show what is in folder:

    • First function create a dropdown box loading dynamically folders or files (with html extension).

    • In second function: if click on an existing subfolder, then open that folder and look inside for html file(s) to open it in a 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')); } }

    I have provided a working demo at tdhtestserver.herobo/.

    SOLVED

    解决方案

    I answer on my question because some of you haven't understood my issue or they don't know how to do it. So I found that was so easy and all i've done was only one line of code.

    high( currentSelectorPath + '/'+selectedOption.getAttribute('data-subfolder')+'/highlighted.html');

    This line was changed everything, where high is a new 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') ); } }

更多推荐

如何用JavaScript找到一个文件?

本文发布于:2023-07-04 09:20:42,感谢您对本站的认可!
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何用   文件   JavaScript

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!