当前位置:Gxlcms > JavaScript > jQuery实现上传之前本地预览图片

jQuery实现上传之前本地预览图片

时间:2021-07-01 10:21:17 帮助过:4人阅读

这次给大家带来jQuery实现上传之前本地预览图片,jQuery实现上传之前本地预览图片的注意事项有哪些,下面就是实战案例,一起来看一下。

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>www.gxlcms.com jquery上传图片本地预览效果</title>
</head>
<body>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.8.2.min.js"></script>
<input id="upload" type="file">
<img id="preview" src="">
<script type="text/javascript">
$('#upload').change(function(){
  // 获取FileList的第一个元素
  alert(document.getElementById('upload').files[0]);
  var f = document.getElementById('upload').files[0];
  src = window.URL.createObjectURL(f);
  document.getElementById('preview').src = src
})
</script>
</body>
</html>

运行效果:

相信看了本文案例你已经掌握了方法,更多精彩请关注Gxl网其它相关文章!

推荐阅读:

Angular如何进行服务端渲染开发

树形控件修改iview步骤说明

以上就是jQuery实现上传之前本地预览图片的详细内容,更多请关注Gxl网其它相关文章!

人气教程排行