判斷客戶端文件時,可以用
複製代碼代碼如下:
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);
判斷服務器端(網絡文件)時,可以用
複製代碼代碼如下:
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 type="file" name="" id="" contentEditable="false" >把contentEditable設置成false限制用戶只能選擇文件,而不能隨便輸入.