成人精品一区二区三区中文字幕-成人精品一区二区三区-成人精品一级毛片-成人精品亚洲-日本在线视频一区二区-日本在线视频免费

導航首頁 ? 技術教程 ? jquery-file-upload 文件上傳帶進度條效果
全站頭部文字 我要出現在這里
jquery-file-upload 文件上傳帶進度條效果 672 2024-03-24   

jQuery File Upload 是一個Jquery圖片上傳組件,支持多文件上傳、取消、刪除,上傳前縮略圖預覽、列表顯示圖片大小,支持上傳進度條顯示;支持各種動態語言開發的服務器端。

效果圖如下所示:

查看圖片

html 部分

<div style="line-height:34px;margin-top:20px;"> 
    <label style="float: left;font-size:14px">上傳文件:</label> 
    <span class="btn btn-success fileinput-button fn-left"> 
   <i class="glyphicon glyphicon-plus"></i> 
   <span>瀏覽...</span> 
   <input type="file" name="file" id="file_upload"> 
  </span> 
    <div style="float: left;margin-left: 20px;font-weight: bold" id="uploadText"></div> 
    </div> 
    <div class="fn-clear"></div> 
    <div id="progress"> 
    <div class="bar" style="width: 0%;"></div> 
    </div> 

css 部分

<link rel="stylesheet"  rel="external nofollow" > 
<link rel="stylesheet"  rel="external nofollow" > 

/*文件上傳控件*/ 
.bar { 
 background-image: -webkit-linear-gradient(top,#5cb85c 0,#449d44 100%); 
 background-image: -o-linear-gradient(top,#5cb85c 0,#449d44 100%); 
 background-image: -webkit-gradient(linear,left top,left bottom,from(#5cb85c),to(#449d44)); 
 background-image: linear-gradient(to bottom,#5cb85c 0,#449d44 100%); 
 filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ff5cb85c', endColorstr='#ff449d44', GradientType=0); 
 background-repeat: repeat-x; 
 height: 20px; 
 font-size: 12px; 
 line-height: 20px; 
 color: #fff; 
 text-align: center; 
 background-color: #428bca; 
 -webkit-box-shadow: inset 0 -1px 0 rgba(0,0,0,.15); 
 box-shadow: inset 0 -1px 0 rgba(0,0,0,.15); 
 -webkit-transition: width .6s ease; 
 -o-transition: width .6s ease; 
 transition: width .6s ease; 
} 
#progress { 
 background-image: -webkit-linear-gradient(top,#ebebeb 0,#f5f5f5 100%); 
 background-image: -o-linear-gradient(top,#ebebeb 0,#f5f5f5 100%); 
 background-image: -webkit-gradient(linear,left top,left bottom,from(#ebebeb),to(#f5f5f5)); 
 background-image: linear-gradient(to bottom,#ebebeb 0,#f5f5f5 100%); 
 filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ffebebeb', endColorstr='#fff5f5f5', GradientType=0); 
 background-repeat: repeat-x; 
 height: 20px; 
 width: 0%; 
 margin-bottom: 20px; 
 overflow: hidden; 
 background-color: #f5f5f5; 
 border-radius: 4px; 
 -webkit-box-shadow: inset 0 1px 2px rgba(0,0,0,.1); 
 box-shadow: inset 0 1px 2px rgba(0,0,0,.1); 
 margin-top: 20px; 
} 
.glyphicon { 
 position: relative; 
 top: 1px; 
 display: inline-block; 
 font-family: 'Glyphicons Halflings'; 
 font-style: normal; 
 font-weight: 400; 
 line-height: 1; 
 -webkit-font-smoothing: antialiased; 
 -moz-osx-font-smoothing: grayscale; 
} 
.glyphicon-plus:before { 
 content: "2b"; 
} 
.btn-success { 
 color: #fff; 
 background-color: #5cb85c; 
 border-color: #4cae4c; 
} 
.btn { 
 display: inline-block; 
 padding: 6px 12px; 
 margin-bottom: 0; 
 font-size: 14px; 
 font-weight: 400; 
 line-height: 1.42857143; 
 text-align: center; 
 white-space: nowrap; 
 vertical-align: middle; 
 cursor: pointer; 
 -webkit-user-select: none; 
 -moz-user-select: none; 
 -ms-user-select: none; 
 user-select: none; 
 background-image: none; 
 border: 1px solid transparent; 
 border-radius: 4px; 
} 

js 部分

<script src="http://www.gimoo.net/admin/assets/plugins/jquery-file-upload/js/vendor/jquery.ui.widget.js"></script> 
<script src="http://www.gimoo.net/admin/assets/plugins/jquery-file-upload/js/jquery.fileupload.js"></script> 
<script type="text/javascript" src="http://www.gimoo.net/t/1905/${pageContext.request.contextPath}/admin/assets/plugins/jquery-1.10.2.min.js"></script> 
<span style="font-family:monospace;font-size:14px;"> <span id="_xhe_cursor"></span>$('#file_upload').fileupload({ 
  dataType: 'json', 
  url:'${pageContext.request.contextPath}/excel/upload', 
  autoUpload:false, 
  add: function (e, data) { 
  $('#progress').css( 
   'width','0%' 
  ); 
  $('#progress .bar').css( 
   'width', '0%' 
  ); 
  $("#uploadText").empty(); 
  var fileType = data.files[0].name.split('.').pop(); 
  // console.log(data); 
  var acceptFileTypes = /xls|xlsx$/i; 
  var size = data.files[0].size; 
  size = (size/1024).toFixed(2);//文件大小單位kb 
  var maxFileSize = 5*1024;//最大允許文件大小單位kb 
  if (!acceptFileTypes.test(fileType)) { 
   new Message({message:"不支持的文件類型,僅支持EXCEL文件"}); 
   return ; 
  } 
  if(size>maxFileSize){ 
   new Message({message:"文件大?。?+size+"KB,超過最大限制:"+maxFileSize+"KB"}); 
   return ; 
  } 
  data.context = $("<button class=' ui-button ui-button-lwhite'/>").text("上傳") 
   .appendTo("#uploadText") 
   .click(function () { 
    data.context = $("<p/>").text("正在上傳...").replaceAll($(this)); 
    data.submit(); 
   }); 
  }, 
  progressall: function (e, data) { 
  var progress = parseInt(data.loaded / data.total * 100, 10); 
  $('#progress').css( 
   'width','100%' 
  ); 
  $('#progress .bar').css( 
   'width',progress + '%' 
  ); 
  }, 
  fail:function (e, data) { 
  new Message({message:"上傳失敗"}); 
  }, 
  done: function (e, data) { 
  console.log(data.files[0]); 
  var fileName = data.files[0].name; 
  var size = data.files[0].size; 
  var obj = data.result; 
  if(obj.success == true){ 
   $("#filePath").val(obj.result.fileId+"&"+obj.result.opLogId); 
   data.context.text("文件上傳已完成!文件名:"+fileName+" 文件大小:"+size+"kb"); 
  }else{ 
   alert(obj.errorMsg); 
  } 
  } 
 });</span> 

XHR響應為Json時IE的下載BUG

這里需要特別注意的是,由于jQuery File Upload都是采用XHR在傳遞數據,服務器端返回的通常是JSON格式的響應,但是IE會將這些JSON響應誤認為是文件傳輸,然后直接彈出下載框詢問是否需要下載。

解決這個問題的方法是必須將相應的Http Head從

Content-Type: application/json 

更改為

Content-Type: text/

總結

以上所述是小編給大家介紹的jquery-file-upload 文件上傳帶進度條效果,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對綠夏網網站的支持!



主站蜘蛛池模板: 三年片大全在线观看| 零食加盟店10大品牌| b超怎么看是男孩女孩| 罗东| naughty america| 朗德海花园场景| 发现一个神奇的定胆方法| 性色视频在线| 女生下体长什么样| 一线钟情 电视剧| 风花电影完整版免费观看| 风月奇谭电影| 猎奇头像| 新烈火情挑| 母亲电影韩国完整版免费观看| 电影《塔蒂亚娜1》演员表| 吃什么皮肤白的最快| 山村老尸图片| 菊次郎的夏天钢琴谱简谱| 黑丝高跟鞋美女| 林熙蕾三级| 电影二嫫1994在线观看完整版| mariaarredondo| 扭扭棒卡皮巴拉教程| 中国黄色片子| 还未入团思想汇报800字| 日韩在线日韩| 桐谷| 蹲着吐一地呕吐视频| 美女热吻| 刘德华表里不一| 婚后三十年电视剧剧情介绍| 十万个冷笑话第二季| 电视剧对峙| 最爱电影免费完整| 男同性恋免费视频| 王韧| 贝子鸟叫声十三口| 影片 - theav| 海滩修学旅程行| 笼中之怒|

?。?!站長長期在線接?。?!

網站、小程序:定制開發/二次開發/仿制開發等

各種疑難雜癥解決/定制接口/定制采集等

站長微信:lxwl520520

站長QQ:1737366103