Solution 1:
Windows Shell is called, but security issues may occur.
* Browsefolder. js
* This file defines the browsefolder () function, which provides a folder selection dialog box.
* Allows you to select system folders.
* The start directory of the folder selection dialog box is
* Shell. browseforfolder (window_handle, message, options, strpath) Function
* Strpath parameter settings
* Example: 0x11 -- my computer
* 0 -- Desktop
* "C: \" -- System Drive C
*
* Use the followingCodeApply this function to an HTML file:
* <SCRIPT src = "browsefolder. js"> </SCRIPT>
* Copy the following code directly to the <script language = "JavaScript">... </SCRIPT> tag;
* Note that due to security issues, you still need to set the following settings to make the JS Code run correctly,
* Otherwise, "no permission" may occur.
*
* 1. Set a trusted site (for example, a local site can be http: // localhost)
* 2. Second, set the following options in the custom settings for trusted site security level:
* "Initialize ActiveX controls that are not marked as secure and run scripts" ---- "enable"
browserfolder. JS: copy Code the code is as follows: /** // ***
path: ID of the object whose value is to be displayed
*****/
function browsefolder (PATH) {
try {
var message = "\ u8bf7 \ u9009 \ u62e9 \ u6587 \ u4ef6 \ u5939 "; // The selection box prompts
var shell = new activexobject ("shell. application ");
var folder = shell. browseforfolder (0, message, 64, 17); // start Directory: My computer
// var folder = Shell. browseforfolder (0, message, 0); // start Directory: desktop
If (folder! = NULL) {
folder = folder. items (); // returns the folderitems object
folder = folder. item (); // returns the folderitem object
folder = folder. path; // return path
If (folder. charat (folder. length-1 )! = "\") {
folder = folder + "\";
}< br> document. getelementbyid (PATH ). value = folder;
return folder;
}< BR >}< br> catch (e) {
alert (E. message);
}< BR >}
When using:Copy codeThe Code is as follows: <TD>
<Input type = "text" name = "path"/>
</TD>
<TD>
<Input type = "button" onclick = "browsefolder ('path ')"
Value = "select the generated path"/>
</TD>
2. solution 2:
Write your own JS selection box to read the local hard disk. The disadvantage is that it looks worse than the previous one. <HTML>Copy codeThe Code is as follows: <Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312">
<Title> untitled document </title>
</Head>
<Body>
<Table border = "0" cellpadding = "0" width = "100%" id = "tb_show">
<Tr>
<TD width = "18%"> file storage location: </TD>
& Lt; TD width = "82%" & gt;
<% -- <HTML: file property = "file" size = "40" styleclass = "inputbox"/> -- %>
<Input name = "backdir" type = "text" value = "C: \" size = "100" width = "500">
</TD>
</Tr>
<Tr>
<TD> directory location: </TD>
<TD>
<Select name = "tables_drive" id = "tables_drives" onchange = "get_drives ()"> </SELECT>
</TD>
</Tr>
<Tr>
<TD colspan = "2">
<Select name = "table_folder" id = "table_folder" size = "10" multiple ondblclick = "get_file ()"> </SELECT>
</TD>
</Tr>
<Tr>
<TD colspan = "2">
<Font color = "red"> Note: Double-click an option in the list box to display the folders in the list box. The first is the root directory. </font>
</TD>
</Tr>
</Table>
</Body>
</Html>
<SCRIPT>
/**//*
* Initialize and put all the system drivers into the table_drives list.
*/
Window. onload = new function Init ()
{
VaR FSO, S, N, E, X;
FSO = new activexobject ("scripting. FileSystemObject ");
E = new enumerator (FSO. Drives );
S = "";
For (;! E. atend (); E. movenext ())
{
X = E. Item ();
S = S + X. driveletter;
S + = ":";
If (X. drivetype = 3)
N = x. sharename;
Else if (X. isready)
N = x. volumename;
Else
N = "[drive not ready]";
S + = N + ",";
}
VaR drives = S. Split (",");
VaR tabledrives = Document. getelementbyid ("tables_drives ");
For (VAR I = 0; I <drives. Length-1; I ++)
{
VaR option = Document. createelement ("option ");
Drives [I]. Split (":");
Option. value = "[" + drives [I]. split (":") [0] + ":]" + drives [I]. split (":") [1];
Option. TEXT = "[" + drives [I]. split (":") [0] + ":]" + drives [I]. split (":") [1];
Tabledrives. Add (option );
}
}
/** // *
* put all the folders on the drive selected in the tables_drives list into the table_folder list
*/
function get_drives ()
{< br> var tabledrives = document. getelementbyid ("tables_drives");
var tablefolders = document. getelementbyid ("table_folder");
for (VAR I = 0; I {< br> If (tabledrives. options [I]. selected = true)
{< br> var FSO, F, FC, s;
var drive = tabledrives. Options [I]. value. split (":") [0]. substring (1, tabledrives. options [I]. value. split (":") [0]. length);
document. getelementbyid ("backdir "). value = drive + ":\\";
FSO = new activexobject ("scripting. fileSystemObject ");
If (FSO. driveexists (drive)
{< br> d = FSO. getdrive (drive);
If (D. isready)
{< br> F = FSO. getfolder (D. rootfolder);
fc = new enumerator (F. subfolders);
S = ""; (;! FC. atend (); FC. movenext ()
{< br> S + = FC. item ();
S + = ",";
}
var Len = tablefolders. options. length;
while (LEN> = 0)
{< br> tablefolders. options. remove (LEN);
Len --;
}< br> var option = document. createelement ("option");
option. value = drive + ":\\";
option. TEXT = drive + ":\\";
tablefolders. add (option);
var folders = S. split (",");
for (j = 0; j {< br> option = document. createelement ("option ");
option. value = folders [J];
option. TEXT = folders [J];
tablefolders. add (option);
}< BR >}< br> else
{< br> alert ("the current content cannot be changed! ")
}< BR >}< br> else
return false;
}< BR >}
/** // *
* double-click an option in table_folder to display the folders in the table_folder list.
*/
function get_file ()
{< br> var tablefolders = document. getelementbyid ("table_folder");
var tabledrives = document. getelementbyid ("tables_drives");
for (VAR I = 0; I {< br> If (tablefolders. options [I]. selected = true)
{< br> var FSO, F, FC, s;
var folderpath = tablefolders. options [I]. value. substring (0, tablefolders. options [I]. value. length);
If (folderpath. charat (folderpath. length-1) = "\")
{< br> document. getelementbyid ("backdir "). value = folderpath;
}< br> else
{< br> document. getelementbyid ("backdir "). value = folderpath + "\";
}
FSO = new activexobject ("scripting. fileSystemObject ");
F = FSO. getfolder (folderpath);
fc = new enumerator (F. subfolders);
S = "";
(;! FC. atend (); FC. movenext ()
{< br> S + = FC. item ();
S + = ",";
}< br> var Len = tablefolders. options. length;
while (LEN> = 0)
{< br> tablefolders. options. remove (LEN);
Len --;
}< br> var opt = "";
var opt1 = "";
for (j = 0; j {< br> var option = document. createelement ("option");
opt = opt + folderpath. split ("\") [J] + "\";
If (j> 0)
{< br> opt1 = OPT;
option. value = opt1.substring (0, opt1.length-1);
option. TEXT = opt1.substring (0, opt1.length-1);
tablefolders. add (option);
}< br> else
{< br> option. value = OPT;
option. TEXT = OPT;
tablefolders. add (option);
}
}
If (tablefolders. Options [0]. value = tablefolders. Options [1]. value)
{
Tablefolders. Options. Remove (1 );
}
If (s! = "")
{
VaR folders = S. Split (",");
For (j = 0; j <folders. Length-1; j ++)
{
Option = Document. createelement ("option ");
Option. value = folders [J];
Option. Text = folders [J];
Tablefolders. Add (option );
}
}
}
}
}
</SCRIPT>
If you have a good solution, please reply and share it.