黑马程序员技术交流社区
标题:
一个图片预览的JS
[打印本页]
作者:
laoyang
时间:
2011-11-21 22:50
标题:
一个图片预览的JS
<form name="form4" id="form4" enctype="multipart/form-data" method="post" action="#">
<input type="file" name="file4" id="file4" onchange="preview4()" />
<img id="pic4" src="" alt="图片在此显示" width="120"/>
</form>
<script type="text/javascript">
function preview4(){
var x = document.getElementById("file4");
var y = document.getElementById("pic4");
if(!x || !x.value || !y) return;
var patn = /\.jpg$|\.jpeg$|\.gif$/i;
if(patn.test(x.value)){
y.src = "file://localhost/" + x.value;
}else{
alert("您选择的似乎不是图像文件。");
}
}
</script>
作者:
朱勋
时间:
2011-11-22 08:47
谢谢楼主分享。{:soso_e113:}
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2