手机
当前位置:查字典教程网 >编程开发 >Javascript教程 >用js实现预览待上传的本地图片
用js实现预览待上传的本地图片
摘要:functionpreview5(){varx=document.getElementById("file5");if(!x||!x.val...

<formname="form5"id="form5"method="post"action="#">

<inputtype="file"name="file5"id="file5"onchange="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>

【用js实现预览待上传的本地图片】相关文章:

jQuery实现给页面换肤的方法

javascript实现炫酷的拖动分页

JavaScript实现弹出模态窗体并接受传值的方法

javascript实现Table排序的方法

jQuery插件实现适用于移动端的地址选择器

Nodejs实现批量下载妹纸图

node.js微信公众平台开发教程

如何实现浏览器上的右键菜单

js实现文本框选中的方法

javascript实现行拖动的方法

精品推荐
分类导航