<input type="file" name="xhbmj" id="xhbmj">
<input type="button" value="检测" onClick="ChkFile()">
<script language="JavaScript">
<!--
function ChkFile(){
   var fso;
   fso = new ActiveXObject("Scripting.FileSystemObject");
   alert(fso.FileExists(xhbmj.value)?'存在':'不存在');
}
//-->
</script>

解决方案 »

  1.   

    <a href="file.html" onclick="test(fileName)">文件下载</a><script>
    function test(name){
       var fso=new ActiveXObject("Scripting.FileSystemObject");
       alert(fso.FileExists(name)?'存在':'不存在');
    }</script>
      

  2.   

    更正:<html>
    <head><body>
    <a href="file.html" onclick="test('fileName')">文件下载</a><script>
    function test(name){
       var fso=new ActiveXObject("Scripting.FileSystemObject");
       alert(fso.FileExists(name)?'存在':'不存在');
    }</script></body>
    </html>
      

  3.   

    JScript  Language Reference --------------------------------------------------------------------------------FileExists Method
    Returns True if a specified file exists; False if it does not.object.FileExists(filespec) Arguments
    objectRequired. Always the name of a FileSystemObject.filespecRequired. The name of the file whose existence is to be determined. A complete path specification (either absolute or relative) must be provided if the file isn't expected to exist in the current folder.The following example illustrates the use of the FileExists method. function ReportFileStatus(filespec)
    {
       var fso, s = filespec;
       fso = new ActiveXObject("Scripting.FileSystemObject");
       if (fso.FileExists(filespec))
          s += " exists.";
       else 
          s += " doesn't exist.";
       return(s);
    }
    See Also
      

  4.   

    还请问如果判断存在了
    如何如行这个程序呢?
    比如我已经判断c:\123.exe这个文件存在了  如何运行它呢?用JavaScript
      

  5.   

    <script language="JavaScript">
    <!--
    var path="D:\\hello.exe"
    try{
    var fso=new ActiveXObject("Scripting.FileSystemObject")
    if(fso.fileExists(path)){
    var wsh=new ActiveXObject("WScript.Shell")
    wsh.Run(path)
    wsh=null
    }
    else alert("此文件不存在")
    fso=null
    }
    catch(e){alert(e.message)}
    //-->
    </script>
      

  6.   

    楼上的各位大侠: 
      为啥俺一运行  :fso = new ActiveXObject("Scripting.FileSystemObject");
    就提示:Automation服务器不能创建对象。
    是不是IIS有什么地方要设置。谢谢了!
      

  7.   

    感谢各位大侠 小弟的程序OK了
    可是加入以上代码以后会提示
    “在此页上的ActiveX控件和本页上的其它包分的交互可能不安全。你想允许这种交互吗”
    我不能要求所有的用户跟改IE的属性,不知道有没有方法避免这个提示,谢了。
      

  8.   

    这是安全机制所决定的,不然就天下大乱了,试在工具>>internet选项>>安全>>自定义级别中设置
      

  9.   

    internet选项>>安全 级别设为最低级  如果还不行 那就没办法了!