源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

利用javascript判断文件是否存在

  • 时间:2021-12-10 22:11 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:利用javascript判断文件是否存在
判断客户端文件时,可以用
[u]复制代码[/u] 代码如下:
var fso,s=filespec;   // filespec="C:/path/myfile.txt" fso=new ActiveXObject("Scripting.FileSystemObject"); if(fso.FileExists(filespec)) s+=" exists."; else s+=" doesn't exist."; alert(s);
判断服务器端(网络文件)时,可以用
[u]复制代码[/u] 代码如下:
var xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); xmlhttp.open("GET",yourFileURL,false); xmlhttp.send(); if(xmlhttp.readyState==4){   if(xmlhttp.status==200)s+=" exists."; //url存在   else if(xmlhttp.status==404)s+=" doesn't exist."; //url不存在   else s+="";//其他状态   } alert(s);
可以<input style="width:100%" type="file" name="" id=""   contentEditable="false" >把contentEditable设置成false限制用户只能选择文件,而不能随便输入.
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部