效果

导入的js和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/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/js/locales/zh.js}"></script>

\\

html

<div class="form-group" id="uiIdcardNumber-img">
<div class="col-sm-4">
<a onclick="showUploadIdCardModel()">上传身份证图片</a>
<script type="text/javascript">
function showUploadIdCardModel(){
$('#uiIdcardNumberModel').modal('show');
}
</script>
<input type="hidden" class="form-control" id="uiIdcardNumberImg1" name="uiIdcardNumberImg1"/>
<input type="hidden" class="form-control" id="uiIdcardNumberImg2" name="uiIdcardNumberImg2"/>
</div>
</div> <div class="modal fade" id="uiIdcardNumberModel" 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="myModalLabel">请上传本人身份证件,确保图片清晰,四角完整</span>
</div>
<div class="modal-body">
<div class="container" style="width: 100%;">
<div class="row" >
<div class="form-group">
<div class="col-sm-6">
<input id="uiIdcardNumberImg1-file" name="file" class="projectfile" type="file"/>
</div>
<div class="col-sm-6">
<input id="uiIdcardNumberImg2-file" name="file" class="projectfile" type="file"/>
</div>
</div>
<div class="form-group">
<div class="col-sm-5">
</div>
<div class="col-sm-2">
<button type="button" id="nqs-add-xiangmu-form-submit" class="btn nqs-btn-inverse" onclick="uiIdcardNumberModel()">完成</button>
<script type="text/javascript">
function uiIdcardNumberModel(){
$("#uiIdcardNumberModel").modal('hide');
//var uiIdcardNumberImg1 = $("#uiIdcardNumberImg1").val();
//var uiIdcardNumberImg2 = $("#uiIdcardNumberImg2").val();
}
</script>
</div>
<div class="col-sm-5">
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>

js

    //初始化fileinput控件(第一次初始化)
var $file1 = $('#uiIdcardNumberImg1-file').fileinput({
language: 'zh', //设置语言
uploadUrl: "/uact/uploadfile", //上传的地址
uploadExtraData:{"type": '1012-0001'},
allowedFileExtensions : ['jpg', 'png','gif'],//接收的文件后缀,
/*deleteUrl:"/uact/deletefile",
deleteExtraData:function() {
var obj = {};
var v = $("#uiIdcardNumberImg1").val(result.fileName);
if( v == null || v == "" || v == undefined ){
v = "--";
}
obj.fileid = v;
obj.type = '1012-0001';
return obj;
},*/
maxFileCount: 1,
enctype: 'multipart/form-data',
showUpload: false, //是否显示上传按钮
showCaption: false,//是否显示标题
showRemove :false,
showBrowse:false,
browseOnZoneClick:true,
autoReplace:true,//是否替换
validateInitialCount:true,
browseClass: "btn btn-primary", //按钮样式
previewFileIcon: "<i class='glyphicon glyphicon-king'></i>",
msgFilesTooMany: "选择上传的文件数量({n}) 超过允许的最大数值{m}!",
layoutTemplates:{
//actionDelete:'',//设置删除按钮的值为空字符串,则去掉图片上面的缩略删除按钮
/*actionUpload:''*/
}
}).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) {
console.log('Key = ' + key);
}).on('filedeleted', function(event, key, jqXHR, data) {
console.log('Key = ' + key);
}).on('filesuccessremove', function(event, id) {//上传成功后删除触发
var v = $("#uiIdcardNumberImg1").val();
if (v != null && v != "" && v != undefined) {
$.ajax({
type: "POST",
cache:false,
async : true,
dataType : "json",
url: "/uact/deletefile",
data: {fileid:v,type:'1012-0001'},
success: function(data){
$("#uiIdcardNumberImg1").val("");
}
});
} else {
return false; // abort the thumbnail removal
}
});
//上传成功后回调函数(使用jquery绑定一个函数)
$file1.on("fileuploaded", function(event, data, previewId, index) {
console.log($file1);
var result = data.response;
if( result.success){
$("#uiIdcardNumberImg1").val(result.fileName);
}
}); //初始化fileinput控件(第一次初始化)
$('#uiIdcardNumberImg2-file').fileinput({
language: 'zh', //设置语言
uploadUrl: "/uact/uploadfile?type=1012-0001", //上传的地址
allowedFileExtensions : ['jpg', 'png','gif'],//接收的文件后缀,
maxFileCount: 1,
enctype: 'multipart/form-data',
showUpload: false, //是否显示上传按钮
showCaption: false,//是否显示标题
showRemove :true,
autoReplace:true,//是否替换
browseClass: "btn btn-primary", //按钮样式
previewFileIcon: "<i class='glyphicon glyphicon-king'></i>",
msgFilesTooMany: "选择上传的文件数量({n}) 超过允许的最大数值{m}!",
layoutTemplates:{
actionDelete:'',//设置删除按钮的值为空字符串,则去掉图片上面的缩略删除按钮
/*actionUpload:''*/
}
});
$("#uiIdcardNumberImg2-file").on("fileuploaded", function(event, data, previewId, index) {
var result = data.response;
if( result.success){
$("#uiIdcardNumberImg2").val(result.fileName);
}
});

修改了部分样式

/* 上传文件 */
.file-preview {
height: 256px!important;
margin-bottom: 20px!important;
}
.file-preview .kv-upload-progress {
display: none!important;
}
.file-preview .kv-upload-progress .progress{
display: none!important;
}
.file-preview .fileinput-remove{
margin-right: 20px!important;
margin-top: 20px!important;
display:none;
}
.file-preview .file-drop-zone{
margin:inherit;
}
.file-preview .file-drop-zone>div{
outline: none!important;
}
.file-preview .file-drop-zone .file-preview-thumbnails{
/* height: 100%!important; */ }
.file-preview .file-drop-zone .file-preview-thumbnails .krajee-default.file-preview-frame {
/* margin-top: -23px!important; */
}
.file-preview .file-drop-zone .file-preview-thumbnails .krajee-default.file-preview-frame .kv-file-content {
height: 100%!important;
}
.file-preview .file-drop-zone .file-preview-thumbnails .file-preview-frame .kv-file-content img{
height: 115px!important;
width: 100%!important;
}
.file-preview .file-drop-zone .file-preview-thumbnails .krajee-default.file-preview-frame .krajee-default.file-preview-frame .file-thumbnail-footer{
height: 165px!important;
}
.file-preview .file-drop-zone .file-preview-thumbnails .krajee-default.file-preview-frame .krajee-default.file-preview-frame .file-thumbnail-footer .file-footer-caption{
eight: 22px!important;
text-overflow: ellipsis!important;
}
.file-drop-zone-title{
font-size: 0.6em!important;
}
.uiIdcardNumberImg{
width: 200px;
height: 140px;
}

bootstrap-3-fileinput上传案例的更多相关文章

  1. Bootstrap FileInput 上传 中文 API 整理

    Bootstrap FileInput 上传  中文 API 整理 上传插件有很多 但是公司用的就是 Bootstrap FileInput 自己就看了看  会用就行 自己都不知道每个值是干嘛用的就问 ...

  2. bootstrap fileinput上传文件

    参考博客:https://blog.csdn.net/linhaiyun_ytdx/article/details/76215974  https://www.cnblogs.com/parker-y ...

  3. Java实现一个简单的文件上传案例

    Java实现一个简单的文件上传案例 实现流程: 1.客户端从硬盘读取文件数据到程序中 2.客户端输出流,写出文件到服务端 3.服务端输出流,读取文件数据到服务端中 4.输出流,写出文件数据到服务器硬盘 ...

  4. TCP通信---文件上传案例、多线程文件上传

    目前大多数服务器都会提供文件上传的功能,由于文件上传需要数据的安全性和完整性,很明显需要使用TCP协议来实现. TCP通信需要创建一个服务器端程序和一个客户端程序,实现客户端向服务器端上传文件 代码实 ...

  5. .net core版 文件上传/ 支持批量上传,拖拽以及预览,bootstrap fileinput上传文件

    asp.net mvc请移步 mvc文件上传支持批量上传,拖拽以及预览,文件内容校验 本篇内容主要解决.net core中文件上传的问题  开发环境:ubuntu+vscode 1.导入所需要的包:n ...

  6. 关于Bootstrap fileinput 上传新文件,移除时触发服务器同步删除的配置

    在Bootstrap fileinput中移除预览文件时可以通过配置initialPreviewConfig: [ { url:'deletefile',key:fileid } ] 来同步删除服务器 ...

  7. bootstrap fileinput 上传文件

    最近用到文件上传功能, 说实话:以前遇到过一次,COPY了别人的代码 结束! 这次又要用,可是看到别人很酷的文件上传功能,心痒了! 好吧.简单的办法,找控件: bootstrap fileinput ...

  8. 【Bootstrap】bootstrap-fileinput上传文件插件

    [bootstrap-fileinput] 这是个据传最好用的bootstrap相关联的文件上传控件,支持拖曳上传,多线程上传,上传文件预览等等功能. 首先还是说一下要引入的一些文件: <lin ...

  9. SpringBoot+BootStrap多文件上传到本地

    1.application.yml文件配置 # 文件大小 MB必须大写 # maxFileSize 是单个文件大小 # maxRequestSize是设置总上传的数据大小 spring: servle ...

随机推荐

  1. BZOJ2141 排队 树状数组 分块

    原文链接https://www.cnblogs.com/zhouzhendong/p/BZOJ2141.html 题目传送门 - BZOJ2141 题意 给定一个序列 $a$ ,先输出原先的逆序对数. ...

  2. 给linux服务器添加一块新的磁盘

    http://www.linuxidc.com/Linux/2011-02/31868.htm 把硬盘装好后,我们用 fdisk -l 查看下: 图中可以看出 /dev/sdb 是500G,新加的硬盘 ...

  3. MVC(面试)

    一般都是三层,表现层(UI).业务逻辑层(BLL).数据访问层(DAL),这些东西不用深究,别为了设计而设计就行.分三层是为了使项目架构体系更加清晰,而且项目参与人员的分工也可以更加明确,也有利于项目 ...

  4. 20165235 Java第一周学习总结

    (# 20165235 Java第一周学习总结 Ubuntu下git的安装与使用 首先Ubuntu下git的安装,使用sudo apt-get install git下载Ubuntu,下载完成后可以用 ...

  5. scrapy之Crawspider 腾讯招聘实战案例

    1. 在虚拟机中cd到项目目录,再运行下面代码创建spider文件: scrapy genspider -t crawl test www.baidu.com 2. spider.py代码 impor ...

  6. P2279 [HNOI2003]消防局的设立

    P2279 [HNOI2003]消防局的设立考场上想出了贪心策略,但是处理细节时有点问题,gg了.从(当前深度最大的节点)叶子节点往上跳k个,在这里设消防局,并从消防局遍历k个距离,标记上. #inc ...

  7. 【H5】-- FormData用法介绍以及实现图片/文件上传--【XUEBIG】

      一.概述 FormData 对象的使用: 1.用一些键值对来模拟一系列表单控件:即把form中所有表单元素的name与value组装成一个queryString 2. 异步上传二进制文件. 二.使 ...

  8. 重温分布式系统的CAP理论

    1. CAP理论的历史 2000年7月,Eric Brewer教授提出CAP猜想:2年后,Seth Gilbert和Nancy Lynch从理论上证明了CAP:之后,CAP理论正式成为分布式计算领域的 ...

  9. Xamarin Essentials教程设备信息DeviceInfo

    Xamarin Essentials教程设备信息DeviceInfo   设备信息包括设备类型.设备种类和操作系统.应用程序通过获取设备信息,可以判断当前程序是否适合在该设备上运行.例如,优酷提供TV ...

  10. c++ STL 数据结构底层结构

    + STL 的实现: 1.vector 底层数据结构为数组 ,支持快速随机访问 2.list 底层数据结构为双向链表,支持快速增删 3.deque 底层数据结构为一个中央控制器和多个缓冲区,详细见ST ...