【IT168技术文档】
function PreviewImage(x) { //var x = document.getElementById('File1'); var xid=x.id+""; var index=xid.substr(xid.length-1,1); if(!x || !x.value) { return false; } var patn = /\.jpg$|\.jpeg$|\.bmp$|\.gif$/i; try { var obj = document.getElementById('PhotoPreviewImg'+index); var barType=index; //默认普通标题图 var width=120; var height=80; if (barType==2) //首页标题图 { width=120; height=90; } else if (barType==3) //焦点图 { width=320; height=240; } if(patn.test(x.value)) { var prvImg = "<img src='file://localhost/" + x.value + "' style='width: "+ width +"px; height: "+ height +"px; border: 1;' />"; var prvImgsrc = 'file://localhost/' + x.value; document.getElementById("PhotoPreviewImg"+index).innerHTML=prvImg; //setTimeout('CheckImg()',300); //imgwh = new Image(); //imgwh.src = "file://localhost/" + x.value; //CheckImg(); } else { alert("您选择的似乎不是图像文件"); return false; } } catch(e) { alert("您选择文件无法预览,或网络故障无法上传,请稍候再试!"); return false; } }