用js实现预览待上传的本地图片
2018-09-26 20:09
<formname=form5id=form5method=postaction=#>
<inputtype=filename=file5id=file5onchange=preview5()/>
</form>
<scripttype=text/javascript>
functionpreview5(){
varx=document.getElementById(file5);
if(!x!x.value)return;
varpatn=/\.jpg$\.jpeg$\.gif$/i;
if(patn.test(x.value)){
vary=document.getElementById(img5);
if(y){
y.src=file://localhost/+x.value;
}else{
varimg=document.createElement(img);img.setAttribute(src,file://localhost/+x.value);
img.setAttribute(width,120);
img.setAttribute(height,90);
img.setAttribute(id,img5);
document.getElementById(form5).appendChild(img);
}
}else{
alert(您选择的似乎不是图像文件。);
}}
</script>