网页选择本地目录路径对话框,使用ACTIVEX对象遍历本地磁盘和目录,只需网页启用相关ACTIVEX的INTERNET选项,对本地浏览器的安全性要求不高,简单易用。

网页选择本地目录路径对话框样例

1.打开主页面"select.html",点击“选择路径”按钮进入路径选择页面“dir.html”,选取本地目录路径

JS+ACTIVEX实现网页选择本地目录路径对话框

2.路径选择页面“dir.html”初始化后,加载本地磁盘驱动,然后根据选择的磁盘路径加载其中的目录。如目录中存在子目录,双击该目录列表项进入下一集目录。

JS+ACTIVEX实现网页选择本地目录路径对话框

3.点击“确定”,关闭选择路径页面"dir.html",将选择的路径值返回到主页面"select.html"文本框上

JS+ACTIVEX实现网页选择本地目录路径对话框
复制代码 代码如下:
/**//*
*初始化,将系统所有的驱动器放入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);
}
get_drives();
}

/**//*
*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;
}
}
}
function get_fileName()
{

var tableFolders = document.getElementById("table_folder");
for ( var i = 0; i < tableFolders.options.length; i++ )
{
if ( tableFolders.options[i].selected == true )
{
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 + "\\";
}
}
}
}
/**//*
*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);
}
}
}
}
}

华山资源网 Design By www.eoogi.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
华山资源网 Design By www.eoogi.com

稳了!魔兽国服回归的3条重磅消息!官宣时间再确认!

昨天有一位朋友在大神群里分享,自己亚服账号被封号之后居然弹出了国服的封号信息对话框。

这里面让他访问的是一个国服的战网网址,com.cn和后面的zh都非常明白地表明这就是国服战网。

而他在复制这个网址并且进行登录之后,确实是网易的网址,也就是我们熟悉的停服之后国服发布的暴雪游戏产品运营到期开放退款的说明。这是一件比较奇怪的事情,因为以前都没有出现这样的情况,现在突然提示跳转到国服战网的网址,是不是说明了简体中文客户端已经开始进行更新了呢?