bootstrap-3-上传图片-列表显示

效果

导入的js和css

<!-- 最新版本的 Bootstrap 核心 CSS 文件 -->
<link rel="stylesheet" href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous"/>
<link th:href="@{/js/bootstrap-fileinput-master/css/fileinput.min.css}" rel="stylesheet"/>
<link th:href="@{/js/bootstrap-fileinput-master/themes/explorer/theme.css}" rel="stylesheet"/>
<link th:href="@{/js/bootstrap-fileinput-master/css/fileinput-rtl.min.css}" rel="stylesheet"/>

<!-- 最新的 Bootstrap 核心 JavaScript 文件 -->
<script src="https://cdn.bootcss.com/jquery/1.12.4/jquery.min.js"></script>
<script src="https://cdn.bootcss.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
<script th:src="@{/js/bootstrap-fileinput-master/js/fileinput.min.js}"></script>
<script th:src="@{/js/bootstrap-fileinput-master/themes/explorer/theme.js}"></script>
<script th:src="@{/js/bootstrap-fileinput-master/js/locales/zh.js}"></script>

html的model

    <div class="modal fade" id="loadingFildPdRecommendModel" tabindex="-1" role="dialog" aria-labelledby="myModalLabel2" data-backdrop=‘static‘>
      <div class="modal-dialog" role="document">
        <div class="modal-content">
          <div class="modal-header">
            <span class="modal-title" id="myModalLabel2">上传附件</span>
          </div>
          <div class="modal-body">
              <div class="container" style="width: 100%;">
                  <div class="row" >
                  <div class="form-group">
                    <div class="col-sm-12">
                        <input id="fild-pd-recommend" name="file" type="file" multiple="multiple" class="file-loading"/>
                    </div>
                  </div>
                </div>
              </div>
          </div>
        </div>
      </div>
    </div>

js

$(function(){
    initRecommentFile();
});
function initRecommentFile(){
    $.post("/pact/findrecommentfile?pdId="+pdId, function (result) {
        var data = result.rows;
        file_upload_Recommend(data);
    });
}

//权益文件上传上传
function file_upload_Recommend(data){
    var preview = [];
    var previewConfig = [];
    for (var i = 0; i < data.length; i++) {
        preview[i]=data[i].prefFinename;
        var o = {};
        o.caption = data[i].prefFinename;
        o.size = "762980";
        o.key = data[i].idStr;
        o.url = "/uact/deletefile?fileid=key&type=1012-0002";//删除地址配置
        previewConfig[i] = o;
    }
    //初始化fileinput控件(第一次初始化)
  $("#fild-pd-recommend").fileinput({
          theme: "explorer",
          uploadUrl: "/uact/uploadfile?type=1012-0002", //上传的地址
          uploadExtraData:{pdId:pdId},
          minFileCount: 0,
          maxFileCount: 20,
          overwriteInitial: false,
          showUpload: true, //是否显示上传按钮
          showCaption: true,//是否显示标题
          showRemove :false,
          showBrowse:true,
          browseOnZoneClick:true,
          autoReplace:true,//是否替换
          validateInitialCount:true,
          allowedFileExtensions:[‘jpg‘, ‘pdf‘, ‘xls‘,‘png‘],
          msgInvalidFileExtension:‘上传文件类型错误"{name}".只能上传"{extensions}"类型的文件‘,
          initialPreview: preview,
          /*initialPreviewAsData: true, // defaults markup
          uploadExtraData: {
              img_key: "1000",
              img_keywords: "happy, nature",

          },*/
          initialPreviewConfig: previewConfig,
          /*initialPreviewConfig: [
              {caption: "Business 1.jpg", size: 762980, url: "/site/file-delete", key: 11},
              {caption: "Business 2.jpg", size: 823782, url: "/site/file-delete", key: 13, previewAsData: false},
              {caption: "PDF Sample.pdf", size: 8000, url: "/site/file-delete", key: 14, type: "pdf"},
              //{caption: "Lorem Ipsum.txt", type: "text", size: 1430, url: "/site/file-delete", key: 12},
              //{type: "video", size: 375000, filetype: "video/mp4", caption: "Krajee Sample.mp4", url: "/site/file-delete", key: 15},
          ],*/
          preferIconicPreview: true, // this will force thumbnails to display icons for following file extensions
          previewFileIcon:‘<i class="glyphicon glyphicon-file"></i> &nbsp;‘,
          previewFileIconSettings: { // configure your icon file extensions
              //‘doc‘: ‘<i class="fa fa-file-word-o text-primary" ><img src="/img/excel.png"/></i>‘,
              ‘xls‘: ‘<i class="fa fa-file-excel-o text-success"><img src="/img/excel.png"/></i>‘,
              //‘ppt‘: ‘<i class="fa fa-file-powerpoint-o text-danger"><img src="/img/excel.png"/></i>‘,
              ‘pdf‘: ‘<i class="fa fa-file-pdf-o text-danger"><img src="/img/pdf.png"/></i>‘,
              //‘zip‘: ‘<i class="fa fa-file-archive-o text-muted"></i>‘,
              //‘htm‘: ‘<i class="fa fa-file-code-o text-info"></i>‘,
              //‘txt‘: ‘<i class="fa fa-file-text-o text-info"><img src="/img/excel.png"/></i>‘,
              //‘mov‘: ‘<i class="fa fa-file-movie-o text-warning"></i>‘,
              //‘mp3‘: ‘<i class="fa fa-file-audio-o text-warning"></i>‘,
              // note for these file types below no extension determination logic
              // has been configured (the keys itself will be used as extensions)
              ‘jpg‘: ‘<i class="fa fa-file-photo-o text-danger"><img src="/img/jpg.png"/></i>‘,
              //‘gif‘: ‘<i class="fa fa-file-photo-o text-muted"></i>‘,
              ‘png‘: ‘<i class="fa fa-file-photo-o text-primary"><img src="/img/jpg.png"/></i>‘
          },
          previewFileExtSettings: { // configure the logic for determining icon file extensions
              ‘doc‘: function(ext) {
                  return ext.match(/(doc|docx)$/i);
              },
              ‘xls‘: function(ext) {
                  return ext.match(/(xls|xlsx)$/i);
              },
              ‘ppt‘: function(ext) {
                  return ext.match(/(ppt|pptx)$/i);
              },
              ‘zip‘: function(ext) {
                  return ext.match(/(zip|rar|tar|gzip|gz|7z)$/i);
              },
              ‘htm‘: function(ext) {
                  return ext.match(/(htm|html)$/i);
              },
              ‘txt‘: function(ext) {
                  return ext.match(/(txt|ini|csv|java|php|js|css)$/i);
              },
              ‘mov‘: function(ext) {
                  return ext.match(/(avi|mpg|mkv|mov|mp4|3gp|webm|wmv)$/i);
              },
              ‘mp3‘: function(ext) {
                  return ext.match(/(mp3|wav)$/i);
              },
          }
     }).on(‘fileclear‘, function(event) {
            console.log("fileclear");
        }).on(‘filecleared‘, function(event) {
            console.log("filecleared");
        }).on(‘fileloaded‘, function(event, file, previewId, index, reader) {
            console.log("fileloaded");
        }).on(‘filereset‘, function(event) {
            console.log("filereset");
        }).on(‘filepreremove‘, function(event, id, index) {
            console.log(‘id = ‘ + id + ‘, index = ‘ + index);
        }).on(‘fileremoved‘, function(event, id, index) {
            console.log(‘id = ‘ + id + ‘, index = ‘ + index);
        }).on(‘filepredelete‘, function(event, key, jqXHR, data) {
            //alert(9);
            /*$.ajax({
                type: "POST",
                cache:false,
                async : true,
                dataType : "json",
                url:  "/uact/deletefile",
                data: {fileid:key,type:‘1012-0002‘},
                success: function(data){
                    console.log(data);
                    $(‘#fild-pd-recommend‘).fileinput(‘reset‘);
                }
           });*/
        }).on(‘filedeleted‘, function(event, key, jqXHR, data) {
            console.log(‘Key = ‘ + key);
        }).on(‘filesuccessremove‘, function(event, id) {//上传成功后删除触发
            alert(id);
     }).on("fileuploaded", function(event, data, previewId, index) {
        console.log(data);
    });
}

列子:http://plugins.krajee.com/file-krajee-explorer-demo

时间: 2024-08-13 18:15:37

bootstrap-3-上传图片-列表显示的相关文章

使用.net mvc4 + bootstrap +uploadify上传图片功能保持前端css一致性

最近使用阿里云空间做个人网站,使用的是.net mvc4 +botstrap,想做个图片上传的功能,查看了郝老师http://www.cnblogs.com/haogj/archive/2013/04/27/3046138.html的博客,功能倒是没什么问题,问题是黑色的上传按钮跟界面不那么和谐,经过半个来小时的思考和调试后,最初的考虑是在button中添加uploadify的span,有点小问题是点击botton前面一小段没有反映,点击后面没有反映.设计margin和padding也没用(技术

JD-Store购物网站复盘——20170312

一.商店技术架构 1.主题 2.涉及技术点: 3.核心业务功能 4.角色 5.用户故事 二.实现步骤 专案基础设施 上传图片模块 购物车 订单 支付&寄信 专案源码 三.第三方服务应用 支付 存储 figaro 机密信息管理 SendCloud服务发送邮件 在线Bug报错 airbrake 一.商店技术架构 1.主题 购物车设计 结帐订单 第三方整合 代码重构 2.涉及技术点: Model 设计原则 自定 before_action 自定义 Routing validation session

仿照Bootstrap的input 修改 upload上传图片的样式

html: <div class="form-group">     <label class="col-sm-3 col-sm-6 control-label">图片</label>     <span class="problem-must"> </span>     <div class="col-sm-8">         <a class

bootstrap ace admin 整合java HTML5 全新高大尚web后台框架

获取[下载地址]   QQ: 313596790   [免费支持更新]支持三大数据库 mysql  oracle  sqlsever   更专业.更强悍.适合不同用户群体[新录针对本系统的视频教程,手把手教开发一个模块,快速掌握本系统]A 代码生成器(开发利器);      增删改查的处理类,service层,mybatis的xml,SQL( mysql   和oracle)脚本,   jsp页面 都生成   就不用写搬砖的代码了,生成的放到项目里,可以直接运行B 阿里巴巴数据库连接池druid

springmvc4 mybatis 整合 框架源码 bootstrap html5 mysql oracle sqlsever spring SSM

获取[下载地址]   QQ: 313596790   [免费支持更新] 三大数据库 mysql  oracle  sqlsever   更专业.更强悍.适合不同用户群体 [新录针对本系统的视频教程,手把手教开发一个模块,快速掌握本系统] A 集成代码生成器 [正反双向(单表.主表.明细表.树形表,开发利器)+快速构建表单; QQ:313596790 freemaker模版技术 ,0个代码不用写,生成完整的一个模块,带页面.建表sql脚本,处理类,service等完整模块 B 集成阿里巴巴数据库连

JavaEE框架Bootstrap、HTML5、jQuery、SpringMVC、Hibernate mybatis

获取[下载地址]   QQ: 313596790   [免费支持更新] 三大数据库 mysql  oracle  sqlsever   更专业.更强悍.适合不同用户群体 [新录针对本系统的视频教程,手把手教开发一个模块,快速掌握本系统] A 集成代码生成器(开发利器);                                         技术:313596790    增删改查的处理类,service层,mybatis的xml,SQL( mysql   和oracle)脚本,   j

java企业级框架 SpringMVC_mybatis or hibernate+ ehcache +shiro+druid+bootstrap+HTML5

获取[下载地址]   QQ: 313596790   [免费支持更新] 支持三大数据库 mysql  oracle  sqlsever   更专业.更强悍.适合不同用户群体 [新录针对本系统的视频教程,手把手教开发一个模块,快速掌握本系统] A 代码生成器(开发利器);       增删改查的处理类,service层,mybatis的xml,SQL( mysql   和oracle)脚本,   jsp页面 都生成    就不用写搬砖的代码了,生成的放到项目里,可以直接运行 B 阿里巴巴数据库连接

SSM springmvc mybatis(oracle 和 mysql sqlserver) HTML5 全新高大尚后台框架 bootstrap

获取[下载地址]   QQ: 313596790   [免费支持更新]三大数据库 mysql  oracle  sqlsever   更专业.更强悍.适合不同用户群体[新录针对本系统的视频教程,手把手教开发一个模块,快速掌握本系统] A集成代码生成器 [正反双向(单表.主表.明细表.树形表,开发利器)+快速构建表单; QQ:313596790freemaker模版技术 ,0个代码不用写,生成完整的一个模块,带页面.建表sql脚本,处理类,service等完整模块B 集成阿里巴巴数据库连接池dru

springmvc mybatis spring bootstrap html5

获取[下载地址]   QQ: 313596790   [免费支持更新]支持三大数据库 mysql  oracle  sqlsever   更专业.更强悍.适合不同用户群体[新录针对本系统的视频教程,手把手教开发一个模块,快速掌握本系统]A 代码生成器(开发利器);      增删改查的处理类,service层,mybatis的xml,SQL( mysql   和oracle)脚本,   jsp页面 都生成   就不用写搬砖的代码了,生成的放到项目里,可以直接运行B 阿里巴巴数据库连接池druid

springmvc整合mybatis框架源码 bootstrap html5

获取[下载地址]   QQ: 313596790   [免费支持更新]支持三大数据库 mysql  oracle  sqlsever   更专业.更强悍.适合不同用户群体[新录针对本系统的视频教程,手把手教开发一个模块,快速掌握本系统]A 代码生成器(开发利器);      增删改查的处理类,service层,mybatis的xml,SQL( mysql   和oracle)脚本,   jsp页面 都生成   就不用写搬砖的代码了,生成的放到项目里,可以直接运行B 阿里巴巴数据库连接池druid