Two solutions for Javascript folder selection box_javascript skills
Call the windows shell, but there will be security issues.
* browseFolder.js
* This file defines the BrowseFolder() function, which will provide A folder selection dialog box
* for users to implement the function of selecting system folders
* The starting directory of the folder selection dialog box is determined by
* Shell.BrowseForFolder(WINDOW_HANDLE, Message, OPTIONS, strPath) strPath parameter setting of function
*
* For example: 0x11--My computer
* 0 --Desktop
* "c:\"--System C drive
*
* Use the following code to apply this function to an HTML file:
*
* Or copy the following code directly to tag;
* Special note is that due to security issues, you also need the following settings to make this JS code run correctly ,
* Otherwise, the problem of "no permissions" will occur.
*
* 1. Set up a trusted site (for example, the local one can be: http://localhost)
* 2. Secondly: In the custom settings of trusted site security level: set the following options
* "Initialize and script run ActiveX controls not marked as safe"----"Enable"
browserFolder.js:
/**//***
path The object id to display the value
****/
function browseFolder(path) {
try {
var Message = "u8bf7u9009u62e9u6587u4ef6u5939"; //Select box prompt message
var Shell = new ActiveXObject("Shell.Application");
var Folder = Shell.BrowseForFolder(0, Message, 64, 17); //The starting directory is: My computer
//var Folder = Shell.BrowseForFolder(0,Message,0); //The starting directory is :Desktop
if (Folder != null) {
Folder = Folder.items(); // Return FolderItems object
Folder = Folder.item(); // Return Folderitem object
Folder = Folder.Path; // Return path
if (Folder.charAt(Folder.length - 1) != "\") {
Folder = Folder "\";
}
document.getElementById (path).value = Folder;
return Folder;
}
}
catch (e) {
alert(e.message);
}
}
When used:
< ;td>
value="Select the generation path" />
2. Solution 2:
Write one yourself js reads the selection box of the local hard disk. The disadvantage is that the appearance is worse than the previous one.
文件保存位置: | <%-- |
目录位置: | |
| |
说明:双击列表框的一个选项,就将该文件夹下面的文件夹显示在该列表框中。第一个就是根目录 |
<script> <br>/**//* <br>* Initialization, put all the drives in the system into the table_drives list <br>*/ <br>window.onload = new function init() <br>{ <br>var fso, s, n, e, x; <br>fso = new ActiveXObject("Scripting.FileSystemObject"); <br>e = new Enumerator(fso.Drives); <br>s = ""; <br>for (; !e.atEnd(); e.moveNext()) <br>{ <br>x = e.item(); <br>s = s x.DriveLetter; <br>s = ":"; <br>if (x.DriveType == 3) <br>n = x.ShareName; <br>else if (x.IsReady) <br>n = x.VolumeName; <br>else <br>n = "[驱动器未就绪]"; <br>s = n ","; <br>} <br>var drives = s.split(","); <br>var tableDrives = document.getElementById("tables_drives"); <br>for ( var i = 0; i < drives.length-1; i ) <BR>{ <BR>var option = document.createElement("OPTION"); <BR>drives[i].split(":"); <BR>option.value = "[" drives[i].split(":")[0] ":]" drives[i].split(":")[1]; <BR>option.text = "[" drives[i].split(":")[0] ":]" drives[i].split(":")[1]; <BR>tableDrives.add(option); <BR>} <BR>} <br><br>/**//* <BR>*All folders on the drive selected in the tables_drives list are placed in the table_folder list <BR>*/ <BR>function get_drives() <BR>{ <BR>var tableDrives = document.getElementById("tables_drives"); <BR>var tableFolders = document.getElementById("table_folder"); <BR>for ( var i = 0; i < tableDrives.options.length; i ) <BR>{ <BR>if ( tableDrives.options[i].selected == true ) <BR>{ <BR>var fso, f, fc, s; <BR>var drive = tableDrives.options[i].value.split(":")[0].substring(1,tableDrives.options[i].value.split(":")[0].length); <BR>document.getElementById("backDir").value = drive ":\"; <BR>fso = new ActiveXObject("Scripting.FileSystemObject"); <BR>if (fso.DriveExists(drive)) <BR>{ <BR>d = fso.GetDrive(drive); <BR>if ( d.IsReady ) <BR>{ <BR>f = fso.GetFolder(d.RootFolder); <BR>fc = new Enumerator(f.SubFolders); <BR>s = ""; <BR>for (;!fc.atEnd(); fc.moveNext()) <BR>{ <BR>s = fc.item(); <BR>s = ","; <BR>} <br><br>var len = tableFolders.options.length; <BR>while(len >= 0) <br>{ <br>tableFolders.options.remove(len); <br>len--; <br>} <br>var option = document.createElement("OPTION"); <br>option.value = drive ":\"; <br>option.text = drive ":\"; <br>tableFolders.add(option); <br>var folders = s.split(","); <br>for ( j = 0; j < folders.length -1; j ) <BR>{ <BR>option = document.createElement("OPTION"); <BR>option.value = folders[j]; <BR>option.text = folders[j]; <BR>tableFolders.add(option); <BR>} <BR>} <BR>else <BR>{ <BR>alert("无法改变当前内容!") <BR>} <BR>} <BR>else <BR>return false; <BR>} <BR>} <BR>} <br><br>/**//* <BR>*table_folder双击选项中的一个选项,就将该文件夹下面的文件夹显示在table_folder列表中。<BR>*/ <BR>function get_file() <BR>{ <BR>var tableFolders = document.getElementById("table_folder"); <BR>var tableDrives = document.getElementById("tables_drives"); <BR>for ( var i = 0; i < tableFolders.options.length; i ) <BR>{ <BR>if ( tableFolders.options[i].selected == true ) <BR>{ <BR>var fso, f, fc, s; <BR>var folderpath = tableFolders.options[i].value.substring(0,tableFolders.options[i].value.length); <BR>if ( folderpath.charAt(folderpath.length-1) == "\" ) <BR>{ <BR>document.getElementById("backDir").value = folderpath; <BR>} <BR>else <BR>{ <BR>document.getElementById("backDir").value = folderpath "\"; <BR>} <br><br><BR>fso = new ActiveXObject("Scripting.FileSystemObject"); <BR>f = fso.GetFolder(folderpath); <BR>fc = new Enumerator(f.SubFolders); <BR>s = ""; <BR>for (;!fc.atEnd(); fc.moveNext()) <BR>{ <BR>s = fc.item(); <BR>s = ","; <BR>} <BR>var len = tableFolders.options.length; <BR>while(len >= 0) <br>{ <br>tableFolders.options.remove(len); <br>len--; <br>} <br>var opt = ""; <br>var opt1 = ""; <br>for ( j = 0; j < folderpath.split("\").length; j ) <BR>{ <BR>var option = document.createElement("OPTION"); <BR>opt = opt folderpath.split("\")[j] "\"; <BR>if ( j > 0) <br>{ <br>opt1 = opt; <br>option.value = opt1.substring(0,opt1.length-1); <br>option.text = opt1.substring(0,opt1.length-1); <br>tableFolders.add(option); <br>} <br>else <br>{ <br>option.value = opt; <br>option.text = opt; <br>tableFolders.add(option); <br>} <br><br>} <br>if ( tableFolders.options[0].value == tableFolders.options[1].value ) <br>{ <br>tableFolders.options.remove(1); <br>} <br>if ( s != "" ) <br>{ <br>var folders = s.split(","); <br>for ( j = 0; j < folders.length -1; j ) <br>{ <br>option = document.createElement("OPTION"); <br>option.value = folders[j]; <br>option.text = folders[j]; <br>tableFolders.add(option); <br>} <br>} <br>} <br>} <br>} <br></script>
如果您还有好的解决方案,回帖分享一下吧.

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



In this article, we will show you how to automatically copy files to another folder on Windows 11/10. Creating backups is necessary to avoid data loss. Data loss can occur due to many reasons such as hard drive corruption, malware attack, etc. You can back up your data manually by using copy and paste method or using third-party tools. Did you know you can automatically back up data on your Windows computer? We'll show you how to do this in this article. How to have files automatically copied to another folder on Windows 11/10 How to use Task Scheduler to automatically copy files and folders to another destination folder on Windows 11/10? This article will provide you with detailed guidance. please

After updating to the latest win11 system, most friends don't know how to encrypt their folders to protect privacy, so we have brought you a method. Let's take a look at how to set a password for a win11 computer folder. How to set a password for a win11 computer folder: 1. First find the folder you want to encrypt. 2. Then right-click the folder and select "Properties". 3. Click "Advanced" under Properties. 4. Check "Encrypt content to protect data" in the menu and click OK. 5. Finally, return to the properties of the folder and click "OK" in the pop-up window.

When you find that one or more items in your sync folder do not match the error message in Outlook, it may be because you updated or canceled meeting items. In this case, you will see an error message saying that your local version of the data conflicts with the remote copy. This situation usually happens in Outlook desktop application. One or more items in the folder you synced do not match. To resolve the conflict, open the projects and try the operation again. Fix One or more items in synced folders do not match Outlook error In Outlook desktop version, you may encounter issues when local calendar items conflict with the server copy. Fortunately, though, there are some simple ways to help

Many users change wallpapers when using their computers. I believe many users are also asking which folder the win11 wallpapers are in? The wallpapers that come with the system are in Wallpaper under the C drive, and the wallpapers saved by users are in the Themes folder of the C drive. Let this site carefully introduce the win11 default wallpaper path sharing for users. Share win11 default wallpaper path 1. The system comes with wallpaper: 1. First enter my computer, and then open the path: C: Windows Web Wallpaper. 2. User-saved wallpapers: 1. Wallpapers installed by users will be saved in: C: Users (user) xx (current user name) AppDataLocalM

The Windows folder contains the Windows operating system and is an important folder in a Windows computer. By default, Windows is installed on the C drive. Therefore, C is the default directory for Windows folders. Every Windows computer has a Windows folder. However, some users reported that two Windows folders were found in the C drive. In this article, we will explain what you can do if you encounter such a situation. Two Windows folders in C drive It is rare to have two Windows folders in C drive. However, if you encounter such a situation, you can use the following suggestions: Run an anti-malware scan to try to find the correct

When using the win10 system, many people are worried about the leakage of confidential files in the computer. In fact, users only need to use the win10 folder password protection function to solve this problem. Today, the editor will help you enable this function. How to set password protection for win10 folders 1. First, you need to select the folder you want to encrypt, right-click the folder, and click Properties in the pop-up option bar. 2. In the properties interface, click Advanced Options in the lower right corner. 3. Enter the advanced properties interface, select the check box before encrypting content to protect data, and then click OK. 4. Then the system will automatically pop up the confirmation attribute change interface, click OK in the interface. 5. In this way, the password protection has been successfully set up, and there will be no impact when using the original account.

Title: Realme Phone Beginner’s Guide: How to Create Folders on Realme Phone? In today's society, mobile phones have become an indispensable tool in people's lives. As a popular smartphone brand, Realme Phone is loved by users for its simple and practical operating system. In the process of using Realme phones, many people may encounter situations where they need to organize files and applications on their phones, and creating folders is an effective way. This article will introduce how to create folders on Realme phones to help users better manage their phone content. No.

In daily life and work, we often need to share files and folders between different devices. Windows 11 system provides convenient built-in folder sharing functions, allowing us to easily and safely share the content we need with others within the same network while protecting the privacy of personal files. This feature makes file sharing simple and efficient without worrying about leaking private information. Through the folder sharing function of Windows 11 system, we can cooperate, communicate and collaborate more conveniently, improving work efficiency and life convenience. In order to successfully configure a shared folder, we first need to meet the following conditions: All devices (participating in sharing) are connected to the same network. Enable Network Discovery and configure sharing. Know the target device
