日期:2014-05-17  浏览次数:20600 次

IE下 js如何清空File
<input id="idFile" name="pic" type="file"/>


//检测程序
var exts = "jpg|gif|bmp|png|jpeg", paths = "|";
function CheckPreview(){
var value = this.file.value, check = true;
if ( !value ) {
check = false; alert("请先选择文件!");
} else if ( !RegExp( "\.(?:" + exts + ")$$", "i" ).test(value) ) {
    check = false;
alert("只能上传以下类型:" + exts);
    if (!window.addEventListener) {      
    document.getElementById("idFile").outerHTML+='';  //IE

    }else { 
     document.getElementById("idFile").value = "";   //FF
    } 
     } else if ( paths.indexOf( "|" + value + "|" ) >= 0 ) {
check = false; alert("已经有相同文件!");
}
return check;
}


在IE下面 如果类型错误只清空一次 继续上传就不会判断也不会清空了
各位高手帮帮 
------解决方案--------------------
写一个COOKIE到客户端,记录一个数,执行后给这个变量数加1!

alert("只能上传以下类型:" + exts);
if (!window.addEventListener) {  
document.getElementById("idFile").outerHTML+=''; //IE

}else { 

这里的if(取COOKIE判断是否大于某个值),如果大于就永远不执行document.getElementById("idFile").outerHTML+=''; //IE

通过客户端的COOKIE这样就变相达到了只清空一次的效果了!