मेरा ऐप एक फ़ोल्डर में लग रही है और फिर एक लटकती मेनू में इसके अंदर सभी फ़ोल्डर और html फ़ाइल दिखाने के लिए, और एक iframe के भीतर किसी भी html फ़ाइलें प्रदर्शित करते हैं। मैं एक फ़ाइल "highlighted.html" जो मैं लटकती मेनू में दिखाने के लिए नहीं करना चाहते हैं कहा जाता है, लेकिन अगर यह मौजूदा निर्देशिका में है मैं एक iframe में स्वचालित रूप से यह दिखाने के लिए चाहते हैं।जावास्क्रिप्ट के साथ फ़ाइल कैसे खोजें?
पहले समारोह एक ड्रॉपडाउन बॉक्स लोड हो रहा है गतिशील बनाने फ़ोल्डर्स या फ़ाइलें (एचटीएमएल विस्तार के साथ):
यह वही फ़ोल्डर में है दिखाने के लिए मेरी कोड है।
दूसरा समारोह में: अगर एक मौजूदा सबफ़ोल्डर पर क्लिक करें, फिर उस फ़ोल्डर को खोलने और 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')); } }
मैं एक काम प्रदान की है http://tdhtestserver.herobo.com/ पर डेमो।
खैर
आप यह नहीं कह सकते हैं '$ (" # myiFrame ") है बदल गया था।attr ('src',/path/to/highlighted) 'क्योंकि पथ गतिशील रूप से' fsStructure [strPath] .subshtmls [i] ' –
@ मार्कसहेनर: कोई जांच नहीं है। $ ("# MyiFrame") कहें। बाद में attr ('src',/path/to/highlighted)। असल में, मामला चुनना है: 1. $ (myframeid) .attr (src ...) और 2. कृपया मेरा एक और जवाब देखें – 3pic