La mia app sta esaminando una cartella e quindi mostra tutte le cartelle e il file html al suo interno in un menu a discesa e visualizza tutti i file html all'interno di un iframe. Ho un file chiamato "evidenziato.html" che non voglio mostrare nel menu a tendina, ma se è nella directory corrente voglio mostrarlo automaticamente in un iframe.Come trovare un file con javascript?
Questo è il mio codice per mostrare ciò che è nella cartella:
Prima funzione di creare una casella a discesa di carico dinamico cartelle o file (con estensione html).
In seconda funzione: se click su una sottocartella esistente, quindi aprire la cartella e guardare all'interno per file html (s) per aprirlo in un 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')); } }
Ho fornito un lavoro demo allo http://tdhtestserver.herobo.com/.
risolto
Non si può dire '$ ("# myiFrame").attr ('src',/percorso/a/evidenziato) 'perché il percorso è creato dinamicamente come' fsStructure [strPath] .subshtmls [i] ' –
@MarkusHayner: no prob '. Dì $ ("# myiFrame"). Attr ('src',/percorso/a/evidenziato) in seguito. IN REALTÀ, si tratta di scegliere tra: 1. $ (myframeid) .attr (src ...) AND 2. Si prega di vedere la mia un'altra risposta – 3pic