欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  web前端

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

程序员文章站 2022-04-01 13:48:04
...
这次给大家带来jQuery实现上传之前本地预览图片,jQuery实现上传之前本地预览图片的注意事项有哪些,下面就是实战案例,一起来看一下。
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>www.jb51.net 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>

运行效果:

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

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

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

推荐阅读:

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

树形控件修改iview步骤说明

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