有时候,我们更新界面信息时会遇到,选择图片后,并不能预览图片,必须提交数据库后才能在页面上显示出来,这样我们该怎样办呢?起始jq为我们提供了两个方法change()和URL.createObjectURL() 直接掉用就行了,废话少说,直接上代码:<!DOCTYPE html><html lang=“en”><head><meta charset=“UTF-8”><meta name=“viewport” content=“width=device-width, initial-scale=1.0”><meta http-equiv=“X-UA-Compatible” content=“ie=edge”><title>Document</title><style></style><script src="./jquery-1.11.0.min.js"></script><!– 有时候,我们更新界面信息时会遇到,选择图片后,并不能预览图片,必须提交数据库后才能在页面上显示出来,这样我们该怎样办呢?起始jq为我们提供了两个方法change()和URL.createObjectURL() 直接掉用就行了,废话少说,直接上代码: –></head><body><input type=“file” class=“file”><br> <div class=“box”><img src="" alt=""></div></body><script> $(function(){ $(".file").change(function(){ $filePath = URL.createObjectURL(this.files[0]); $(‘img’).attr(“src”,$filePath) })})</script></html>