【原】jquery图片预览
平时我们在做图片上传的时候,如果可以让用户选择图片的时候,看到图片的效果,那这样用户体验会好很多,因为用户可以就可以决定是否继续用这张图片,尤其是和ajaxuploadfile结合使用的时候,图片的预览让其做的更加的完美。
代码是这样的
$(function() {
var path,
clip = $("#img"), //图片显示的地址 img的id <img id="#img" src="#" />
FileReader = window.FileReader;
$("#file").change(function() { //#file是 <input type='file' id="file" />
if (FileReader) {
var reader = new FileReader(),
file = this.files[0];
reader.onload = function(e) {
clip.attr("src", e.target.result);
};
reader.readAsDataURL(file);
}
else {
path = $(this).val();
if (/"\w\W"/.test(path)) {
pathpath = path.slice(1,-1);
}
clip.attr("src",path);
}
});
})
其实原理就是读取input type="file" 的路径,将这个路劲赋给 要显示的img的src那里
html代码
<!-- 上传的input -->
<input type="file" id="file"> <!-- 预览的图片我想在这个img这里显示 -->
<img src="" id="img" />
【原】jquery图片预览的更多相关文章
- 强大的图片展示插件,JQuery图片预览展示插件
只需要引入JQuery.js , viewer.css 和 viewer.js <!DOCTYPE html> <html lang="en"> <h ...
- jQuery PC端图片预览,鼠标移上去查看大图
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- dwz+jquery+fileupload+springmvc实现文件上传 及图片预览
1 前台jsp:文件的上传利用了iframe实现局部刷新功能.使用了apache的fileupload组件,用到的jar: commons-fileupload.jar,commons-io.jarD ...
- jquery解决file上传图片+图片预览
js解决file上传图片+图片预览 demo案例中代码为js原生控制,可以根据项目的需求修改为jquery操作 <!DOCTYPE html><html lang="en& ...
- jquery实现上传图片及图片大小验证、图片预览效果代码
jquery实现上传图片及图片大小验证.图片预览效果代码 jquery实现上传图片及图片大小验证.图片预览效果代码 上传图片验证 */ function submit_upload_picture() ...
- dropzonejs中文翻译手册 DropzoneJS是一个提供文件拖拽上传并且提供图片预览的开源类库.
http://wxb.github.io/dropzonejs.com.zh-CN/dropzonezh-CN/ 由于项目需要,完成一个web的图片拖拽上传,也就顺便学习和了解了一下前端的比较新的技术 ...
- 适用于各浏览器支持图片预览,无刷新异步上传js插件
文件上传无疑是web应用中一个非常常用的功能,不管是PHP.jsp还是aspx.mvc等都会需要文件上传,但是众所周知当使用自带的文件上传功能时总会出现页面刷新的情况.当然现在有了html5这个好东西 ...
- C#上传图片和生成缩略图以及图片预览
因工作需要,上传图片要增加MIME类型验证和生成较小尺寸的图片用于浏览.根据网上代码加以修改做出如下效果图: 前台代码如下: <html xmlns="http://www.w3.or ...
- js图片预览插件,不涉及上传
小小的几十行代码,很牛逼,很实用. 支持多个图片的预览,只要new多个对象就行了. html如下 <!-- zhouxiang www.zhou-xiang.com --> <!DO ...
随机推荐
- Codeforces Round #359(div 2)
A:= v = B:^ w ^ C:一天n个小时,一个小时m分(n,m十进制),一个手表有两部分,左边表示时,右边表示分,但都是7进制,而且手表上最多只能有7个数字且数字不能重复,现在要你算出能正确表 ...
- Congruence relation 同余关系
https://en.wikipedia.org/wiki/Congruence_relation https://zh.wikipedia.org/wiki/%E5%90%8C%E9%A4%98%E ...
- CXF集成Spring实现webservice的发布与请求
CXF集成Spring实现webservice的发布(服务端) 目录结构: 主要代码: package com.cxf.spring.pojo; public class User { int id ...
- android 圆角图片的实现
图片展示的时候总觉的直角的图片不好看?好办法来了!-- public class ToRoundCorner extends Activity{ public Bitmap toRoundCorner ...
- Linux下运行memcached失败
Linux下运行memcached失败 1.错误信息如下 [root@localhost ~]# memcached can't run as root without the -u switch 2 ...
- js打字机效果实现
<!DOCTYPE html><html> <head> <meta charset="UTF-8"> <title>打 ...
- MySQL的热备percona-xtrabackup、innobackupex的安装方法
http://blog.csdn.net/dbanote/article/details/13295727 http://blog.csdn.net/yangzhawen/article/detail ...
- Dubbo系列(2)_RPC介绍
一.本文目的 主要介绍RPC的一些概念和应用. 二.为什么要介绍RPC DUBBO是一个分布式服务框架,致力于提供高性能和透明化的RPC远程服务调用方案,是阿里巴巴SOA服务化治 ...
- Apache Shiro和Spring Security的详细对比
参考资料: 1)Apache Shiro Apache Shiro:http://shiro.apache.org/ 在Web项目中应用 Apache Shiro:http://www.ibm.com ...
- liunx下tomcat启动 Cannot find ./catalina.sh
执行启动tomcat命令./startup.sh 提示 Cannot find ./catalina.sh The file is absent or does not have execute pe ...