1.页面首先引入jquery,版本不要低于1.6
   <script src="../js/jquery.min.js"></script>
2.其次页面引入对应的这个五个js,按顺序放置
<script src="../js/jquery.ui.widget.js"></script>
<script src="../js/jquery.iframe-transport.js"></script>
   <script src="../js/jquery.fileupload.js"></script>
   <script src="../js/jquery.fileupload-process.js"></script>
   <script src="../js/jquery.fileupload-ui.js"></script>
3.html结构如下:
  <div class="control-group"><label>上传头像:</label>
<div class="controls upload-bg"><!---->
<input class="upload" id="file" type="file" name="file">
<img src="" style="display:none;width:100%;height:100%" id="target" alt="[Jcrop Example]"/>
<input type="hidden" value="" id="url">
</div>
<p class="reupload">重新上传
<input class="imgEditor" id="uploadNext" type="file" name="file" value=""/>
  </p>
</div>
这个样式是这样的:
4.css样式如下:如有些结构和样式不一致的,希望自己调整一下
  /*上传图片*/
.control-group .upload {
width: 100%;
height: 100%;
opacity: 0;
cursor: pointer;
} .control-group .upload-bg {
width: 240px;
height: 240px;
position: relative;
border: 1px solid #ccc;
background: url("../images/upload.png") center no-repeat;
margin-left: 200px;
margin-top: -25px;
}
.control-group .upload-bg:hover {
border: 1px dashed #0000FF;
transition: border 1s;
}
.control-group .upload-bg p, .imgEditor {
position: absolute;
bottom: 0;
display: none;
text-align: center;
width: 100%;
margin: 0;
background: #210606;
opacity: 0.6;
color: #ccc;
cursor: pointer; }
.control-group .upload-bg:hover {
border: 1px dashed #0000FF;
transition: border 1s;
}
.fm .reupload{margin-bottom:0 !important;}
.control-group .upload-bg p, .imgEditor {
position: absolute;
bottom: 0;
display: none;
text-align: center;
width: 100%;
margin: 0;
background: #210606;
opacity: 0.6;
color: #ccc;
cursor: pointer; }
.imgEditor {
opacity: 0;
z-index: 2;
left: 0;
height: 100% !important;
display: block; } .reupload{
margin-top:2px;
position: relative;
height: 24px !important;
width: 243px !important;
margin-left: 200px;
line-height: 24px;
background: #9999CC;
display: none;
}
5.上传的js部分:
function imgUpLoad(eleId) {
$('#' + eleId).fileupload({
autoUpload: true,//自动上传
url: "http://xxxxx.url",//ַ上传图片对应的地址
dataType: 'json',
done: function (e, data) {
var oimage = data, _this = $('#' + eleId);
if (eleId == 'file') {
_this.hide();
_this.siblings('img').attr('src', oimage.result.url).show();
$('.reupload').show();//第一次上传完成,显示重新上传 } else {//重新上传
_this.closest('.control-group').find('#target').attr('src', oimage.result.url);
}
}
})
}
6.最后上传完成之后是这样的(其实还有裁剪的功能,下一篇介绍)

最新文章

  1. 在 Ubuntu 14.10 中借用 Windows 的字体
  2. jQuery中attr()、prop()、data()用法及区别
  3. bootstrap 无限极菜单
  4. 【读书笔记】WebApi 和 SPA(单页应用)--knockout的使用
  5. weback学习笔记
  6. jQuery插件:跨浏览器复制jQuery-zclip
  7. PAT 解题报告 1009. Product of Polynomials (25)
  8. VNC常用操作及常见问题解决办法汇总
  9. 如何引用CSS样式表
  10. SQL允许远程访问
  11. 【S】【S】【S】一大波前端干货整合(一)
  12. 使用ant的war任务打包j2ee web项目
  13. SQL视图和多表连接
  14. asp.net接收发送的xml字符串数据
  15. asp.net中怎样调用存储过程和存储过程的写法(转载,留着自己看)
  16. Linux 遭入侵,挖矿进程被隐藏排查记录
  17. python之旅九【第九篇】socket
  18. tcp的三次握手,四次挥手
  19. ubuntu16安装dhcp server
  20. php 文件上传 $_FILES 错误码

热门文章

  1. 怎么样写一个能告诉你npm包名字是否被占用的工具
  2. 验证控件 .net
  3. 检测UTF-8编码
  4. VIM命令总结【转】
  5. 获取url的参数
  6. CC通信软件list
  7. 在eclipse配置Maven
  8. hdu 6109 数据分割
  9. listen 74
  10. Nginx均衡负载配置