javascript实现读取本地的目录 你想攻击人家电脑啊!
------------------------------------------------
哈哈 开玩笑!出于安全上的考虑,应该不推荐使用的吧  ------我瞎说的

解决方案 »

  1.   

    <input type=button value=选择路径 onclick='javascript: alert(new ActiveXObject("Shell.Application").BrowseForFolder(0, "请选择路径", 0, "").Items().Item().Path)'>
      

  2.   

    to:meizz(梅花雪)
    需要直接显示在页面上。。不要弹出一个窗口咯。这样子的可以实现吗?
      

  3.   

    来帮写一个,但用了fso,会有activex警告。
    <input type="text" name="path" size="93">
    <input type="submit" value="浏览..." name="B5" onclick="selfile.click();">
    <span style="visibility:hidden;"><input type="file" name="selfile" size="1" style="width: 90; height: 19" onchange="selpathf();"></span>
    <br>
    <span id=liststr>
    <select size="20" name="listfile" style="width: 740; height: 250" ondblclick="getlog(path.value,listfile.selectedIndex[1])">
    <option value="asd">尚未读取!</option>
    </select>
    </span>
    <br>
    文本文件读取:<br>
    <textarea rows="16" name="input_cad" cols="49" wrap=off style="text-align: left; height:250; width:740"></textarea>
    <SCRIPT LANGUAGE="JavaScript">//----------------------------------------------------------------------------------//
    //                   下面为js写的txt文件浏览功能  //
    //                  基本思路 //
    //                   1、写bat文件,内部内容为dir,并输出定向到某文本文件中  //
    //                   2、将该文本文件中的内容读出  //
    //                   3、将该文本文件删除 //
    //----------------------------------------------------------------------------------//txtfile="filelist.lis"; //临时目录文件名
    batfile="filelist.bat"; //临时批处理文件
    filepath="c:\\"; //当前目录-全局变量-设置初始目录//选取文件后响应-程序入口
    function selpathf()
    {
    str=selfile.value;
    pathstr=str.substring(0,str.lastIndexOf("\\")+1);
    path.value=pathstr;
    showlist(); //打开列表
    }//打开文件夹列表
    function showlist()
    {
    filepath=path.value; //从外部读路径至全局变量var fso,tf; 
    fso = new ActiveXObject("Scripting.FileSystemObject"); 
    tf = fso.CreateTextFile(filepath+batfile,true); 
    tf.WriteLine("cd "+filepath) ; 
    tf.WriteLine("dir "+filepath+"*.txt /b > "+filepath+txtfile) ; 
    tf.Close(); var wsh=new ActiveXObject("wscript.shell")
    wsh.run(filepath+batfile)
    cmdstr="open1txt("+filepath+","+txtfile+","+batfile+");"
    setTimeout("open1txt()",400);
    }//打开文件夹列表并写到列表当中,之后删除文件
    function open1txt()
    {
    fso = new ActiveXObject("Scripting.FileSystemObject"); 
    ts = fso.OpenTextFile(filepath+txtfile, 1);
    listrcont='';
    while(!ts.AtEndOfStream)
    {
    s=ts.ReadLine();
    listrcont+='<option value='+s+'>'+s+'</option>';
    }
    liststr.innerHTML='<select size="20" name="listfile" style="width: 740; height: 250" ondblclick="getlog(path.value,listfile.value)">'+listrcont+'</select>';
    ts.Close(); 
    fso.DeleteFile(filepath+txtfile,1); 
    fso.DeleteFile(filepath+batfile,1); 
    }//读取文件内容
    function getlog(spath,sfile)
    {
    pathfile=spath+sfile+"";
    fso = new ActiveXObject("Scripting.FileSystemObject"); 
    ts = fso.OpenTextFile(pathfile,1); 
    var logstr = ts.ReadAll();
    input_cad.value=logstr;
    }path.value=filepath;
    showlist(); //打开列表
    </SCRIPT>