laravel下 jquery-from 上传图片立即显示
2017-06-19 11:54
274 查看
<style> .btn{position: relative;overflow: hidden;margin-right: 4px;display:inline-block; *display:inline;padding:4px 10px 4px;font-size:14px;line-height:18px; *line-height:20px;color:#fff; text-align:center;vertical-align:middle;cursor:pointer;background:#5bb75b; border:1px solid #cccccc;border-color:#e6e6e6 #e6e6e6 #bfbfbf; border-bottom-color:#b3b3b3;-webkit-border-radius:4px; -moz-border-radius:4px;border-radius:4px;} .btn input{position: absolute;top: 0; right: 0;margin: 0;border:solid transparent; opacity: 0;filter:alpha(opacity=0); cursor: pointer;} .progress{position:relative; margin-left:100px; margin-top:-24px; width:200px;padding: 1px; border-radius:3px; display:none} .bar {background-color: green; display:block; width:0%; height:20px; border-radius:3px; } .percent{position:absolute; height:20px; display:inline-block; top:3px; left:2%; color:#fff } .files{height:22px; line-height:22px; margin:10px 0} .delimg{margin-left:20px; color:#090; cursor:pointer} </style> <script type="text/javascript" src="{{asset('lib/jquery-form.js')}}"></script>
<body>
<div class="btn"> <span>添加附件</span> <input id="fileupload" type="file" name="mypic"> </div> <div class="progress"> <span class="bar"></span><span class="percent">0%</span > </div> <div class="files"></div> <div id="showimg"></div> </body> <script> $(function () { var bar = $('.bar'); var percent = $('.percent'); var showimg = $('#showimg'); var progress = $(".progress"); var files = $(".files"); var btn = $(".btn span"); $("#fileupload").wrap("<form id='myupload' action='{{route('consultList')}}' method='post'enctype='multipart/form-data'></form>"); $("#fileupload").change(function(){ //选择文件 $("#myupload").ajaxSubmit({ dataType: 'json', //数据格式为json beforeSend: function() { //开始上传 showimg.empty(); //清空显示的图片 progress.show(); //显示进度条 var percentVal = '0%'; //开始进度为0% bar.width(percentVal); //进度条的宽度 percent.html(percentVal); //显示进度为0% btn.html("上传中..."); //上传按钮显示上传中 }, uploadProgress: function(event, position, total, percentComplete) { var percentVal = percentComplete + '%'; //获得进度 bar.width(percentVal); //上传进度条宽度变宽 percent.html(percentVal); //显示上传进度百分比 }, success: function(data) { //成功 //获得后台返回的json数据,显示文件名,大小,以及删除按钮 files.html("<b>"+data.name+"("+data.size+"k)</b><span class='delimg' rel='"+data.pic+"'>删除</span>"); //显示上传后的图片 var img = "http://laravel/upload/"+data.pic; showimg.html("<img src='"+img+"'>"); btn.html("添加附件"); //上传按钮还原 }, error:function(xhr){ //上传失败 btn.html("上传失败"); bar.width('0'); files.html(xhr.responseText); //返回失败信息 } }); }); }); $(function () { $(".delimg").live('click',function(){ var pic = $(this).attr("rel"); $.post("{{route('consultList')}}?act=delimg",{imagename:pic},function(msg){ if(msg==1){ files.html("删除成功."); showimg.empty(); //清空图片 progress.hide(); //隐藏进度条 }else{ alert(msg); } }); }); }); </script>
相关文章推荐
- 自定义控件实现无刷新上传图片,立即显示缩略图,保存图片缩略图<原创>
- 自定义控件实现无刷新上传图片,立即显示缩略图,保存图片缩略图<原创>
- jquery在火狐浏览中上传图片并显示
- asp.net 自定义控件实现无刷新上传图片,立即显示缩略图,保存图片缩略图
- jQuery插件之ajaxFileUpload(异步上传图片并实时显示,并解决onchange后ajaxFileUpload失效问题)
- tomcat8 照成图片上传后不能立即显示
- 利用JQuery及其插件做出一个上传图片及利用prototype插件显示剪裁图片的例题
- 上传后立即显示图片以及urldecode
- 基于JQuery的图片上传预览插件(图片预览、过滤文件类型、限制图片大小、图片显示后回调)
- PHP JS JQ 异步上传并立即显示图片
- jQuery插件之ajaxFileUpload(异步上传图片并实时显示,并解决onchange后ajaxFileUpload失效问题)
- 关于ajaxfileupload.js一些问题和上传图片就立即显示图片功能
- asp.net 自定义控件实现无刷新上传图片,立即显示缩略图,保存图片缩略图
- 利用jQuery插件imgAreaSelect实现图片上传裁剪(同步显示图像位置信息)
- 上传图片立即显示
- jquery+php+ajax显示上传进度的多图片上传并生成缩略图代码
- Thinkphp+Jqueryfrom图片异步上传预览
- SpringMVC多个文件上传及上传后立即显示图片功能
- jquery中使用Ajax异步上传图片(即当图片只要上传,就可以立即看到)
- 简单.net上传图片 jquery预览显示 无验证