凯发天生赢家一触即发官网的解决方案1:
调用windows 的shell,但会有安全问题.
* browsefolder.js
* 该文件定义了browsefolder()函数,它将提供一个文件夹选择对话框
* 以供用户实现对系统文件夹选择的功能
* 文件夹选择对话框起始目录由
* shell.browseforfolder(window_handle, message, options, strpath)函数
* 的strpath参数设置
* 例如:0x11--我的电脑
* 0 --桌面
* "c:\\"--系统c盘
*
* 用如下代码把该函数应用到一个html文件中:
*
* 或把下面代码直接copy到标签中;
* 特别注意的是,由于安全方面的问题,你还需要如下设置才能使本js代码正确运行,
* 否者会出现"没有权限"的问题.
*
* 1、设置可信任站点(例如本地的可以为:http://localhost)
* 2、其次:可信任站点安全级别自定义设置中:设置下面的选项
* "对没有标记为安全的activex控件进行初始化和脚本运行"----"启用"
browserfolder.js:
/**//***
path 要显示值的对象id
****/
function browsefolder(path) {
try {
var message = "\u8bf7\u9009\u62e9\u6587\u4ef6\u5939"; //选择框提示信息
var shell = new activexobject("shell.application");
var folder = shell.browseforfolder(0, message, 64, 17);//起始目录为:我的电脑
//var folder = shell.browseforfolder(0,message,0); //起始目录为:桌面
if (folder != null) {
folder = folder.items(); // 返回 folderitems 对象
folder = folder.item(); // 返回 folderitem 对象
folder = folder.path; // 返回路径
if (folder.charat(folder.length - 1) != "\\") {
folder = folder "\\";
}
document.getelementbyid(path).value = folder;
return folder;
}
}
catch (e) {
alert(e.message);
}
}
使用的时候:
<td>
<input type="text" name="path" />
td>
<td>
<input type="button" onclick="browsefolder('path')"
value="选择生成路径" />
td>
2.凯发天生赢家一触即发官网的解决方案二:
自己写一个js读取本地硬盘的选择框, 缺点是外观上较上一个差一些.
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=gb2312">
<title>无标题文档title>
head>
<body>
<table border="0" cellpadding="0" width="100%" id="tb_show">
<tr>
<td width="18%">文件保存位置:td>
<td width="82%">
<%--<html:file property="file" size="40" styleclass="inputbox"/>--%>
<input name="backdir" type="text" value ="c:\" size="100" width="500">
td>
tr>
<tr>
<td>目录位置: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">说明:双击列表框的一个选项,就将该文件夹下面的文件夹显示在该列表框中。第一个就是根目录font>
td>
tr>
table>
body>
html>
<script>
/**//*
*初始化,将系统所有的驱动器放入table_drives列表
*/
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 = "[驱动器未就绪]";
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);
}
}
/**//*
*tables_drives列表中选中的驱动器上所有文件夹放入table_folder列表中
*/
function get_drives()
{
var tabledrives = document.getelementbyid("tables_drives");
var tablefolders = document.getelementbyid("table_folder");
for ( var i = 0; i < tabledrives.options.length; i )
{
if ( tabledrives.options[i].selected == true )
{
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))
{
d = fso.getdrive(drive);
if ( d.isready )
{
f = fso.getfolder(d.rootfolder);
fc = new enumerator(f.subfolders);
s = "";
for (;!fc.atend(); fc.movenext())
{
s = fc.item();
s = ",";
}
var len = tablefolders.options.length;
while(len >= 0)
{
tablefolders.options.remove(len);
len--;
}
var option = document.createelement("option");
option.value = drive ":\\";
option.text = drive ":\\";
tablefolders.add(option);
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);
}
}
else
{
alert("无法改变当前内容!")
}
}
else
return false;
}
}
}
/**//*
*table_folder双击选项中的一个选项,就将该文件夹下面的文件夹显示在table_folder列表中。
*/
function get_file()
{
var tablefolders = document.getelementbyid("table_folder");
var tabledrives = document.getelementbyid("tables_drives");
for ( var i = 0; i < tablefolders.options.length; i )
{
if ( tablefolders.options[i].selected == true )
{
var fso, f, fc, s;
var folderpath = tablefolders.options[i].value.substring(0,tablefolders.options[i].value.length);
if ( folderpath.charat(folderpath.length-1) == "\\" )
{
document.getelementbyid("backdir").value = folderpath;
}
else
{
document.getelementbyid("backdir").value = folderpath "\\";
}
fso = new activexobject("scripting.filesystemobject");
f = fso.getfolder(folderpath);
fc = new enumerator(f.subfolders);
s = "";
for (;!fc.atend(); fc.movenext())
{
s = fc.item();
s = ",";
}
var len = tablefolders.options.length;
while(len >= 0)
{
tablefolders.options.remove(len);
len--;
}
var opt = "";
var opt1 = "";
for ( j = 0; j < folderpath.split("\\").length; j )
{
var option = document.createelement("option");
opt = opt folderpath.split("\\")[j]"\\";
if ( j > 0)
{
opt1 = opt;
option.value = opt1.substring(0,opt1.length-1);
option.text = opt1.substring(0,opt1.length-1);
tablefolders.add(option);
}
else
{
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>
如果您还有好的凯发天生赢家一触即发官网的解决方案,回帖分享一下吧.