1.说明

1)createObjectURL

  作用:创建url(creates  a URL for the specified object);

  语法:var url = URL.createObjectURL(object,options);

  参数说明:1)object可以包含下列类型:Blob,MSStram,IstaorageItem,MediaCapture,IRandomAccessStreamWithContentType,

       2)options若设置为true,则是oneTimeOnly attribute,doesn't need to be revoked once used,即只是用一次

2)revokeObjectURL

  作用:将对象鱼url关联(rovokes a URL from  a document and frees the object associated with that URL)

  语法:var retval = URL.revokeObjectURL(url);

2.例子

<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<style>
#preview {
width: 300px;
height: 300px;
overflow: hidden;
}
#preview img {
width: 100%;
height: 100%;
}
</style>
<script src="../js/jquery-1.9.1.min.js"></script>
</head>
<body>
<form enctype="multipart/form-data" action="" method="post">
<input type="file" name="imageUpload"/>
<div id="preview" style="width: 300px;height:300px;border:1px solid gray;"></div>
</form>
</body>
<script type="text/javascript">
$(function(){
$('[type="file"]').change(function(e){
var file = e.target.files[0];
preview(file);
});
})
function preview(file){
var img = new Image();
url = img.src=URL.createObjectURL(file);
var $img = $(img);
img.onload = function(e){
URL.revokeObjectURL(url);
$('#preview').empty().append($img);
}
}
</script>
</html>

效果如下:(点击上传后立刻在页面上显示)

最新文章

  1. Ruby Unit Test
  2. [Redis]通过代码配置Redis
  3. Mark一下,一上午就这么过去了,关于客户端连接oracle10G的问题
  4. android学习笔记 对话框合集
  5. xml bug之cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration...
  6. stm32f407 定时器 用的APB1 APB2 及 定时器频率
  7. 【转】spring管理属性配置文件properties——使用PropertiesFactoryBean|spring管理属性配置文件properties——使用PropertyPlaceholderConfigurer
  8. linux4.1.6+aufs4.1
  9. Entity Framework Core 2.1 Preview1 新增功能简介
  10. 学习ASP.NET Core Razor 编程系列九——增加查询功能
  11. [题解]洛谷P2709 小B的询问
  12. June. 22 2018, Week 25th. Friday
  13. AngularJS 作用域(Scope)
  14. Django web框架-----url path name详解
  15. linux find命令-print0和xargs中-0使用技巧
  16. java中类加载时机
  17. Ngui Tween 组合动画 group
  18. Yii实战中8个必备常用的扩展,模块和widget
  19. HDU 2829 区间DP &amp; 前缀和优化 &amp; 四边形不等式优化
  20. 【WP8】为Webbrowser添加ScrollBar

热门文章

  1. hook研究结果备忘
  2. window7 远程连接 拒绝访问
  3. BestCoder冠军赛 - 1005 Game 【DP】
  4. js的new操作符
  5. cenos6.5 64位下PHP远程连接sql server2008成功案例
  6. JavaScript回调函数的理解
  7. .Net操作XML文件
  8. 利用Range改变光标位置
  9. cas sso单点登录系列6_cas单点登录防止登出退出后刷新后退ticket失效报500错
  10. PAT-1041 Be Unique