效果

导入的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. Promise-async-await处理函数

    /*function request() { // 此处的request返回的是一个Promise return new Promise((resolve, reject) => { ajax( ...

  2. BZOJ3561 DZY Loves Math VI 数论 快速幂 莫比乌斯反演

    原文链接http://www.cnblogs.com/zhouzhendong/p/8116330.html UPD(2018-03-26):回来重新学数论啦.之前的博客版面放在更新之后的后面. 题目 ...

  3. 数据特征分析:3.统计分析 & 帕累托分析

    1.统计分析 统计指标对定量数据进行统计描述,常从集中趋势和离中趋势两个方面进行分析 集中趋势度量 / 离中趋势度量 One.集中趋势度量 指一组数据向某一中心靠拢的倾向,核心在于寻找数据的代表值或中 ...

  4. day27 软件开发规范,以及面相对象回顾

    面向对象所有内容回顾: # 面向对象 # 类 :一类具有相同属性和方法的事物 #类的定义:class #类中可以定义的方法种类: #普通方法 self 对象 #类方法 cls @classmethod ...

  5. day11 装饰器---函数的使用方法

    这个是一个难点,以后面试会经常出现的,要搞懂! 装饰器升级版,进阶内容1: def outer(flag): def wrapper(func): def inner(*args,**kwargs): ...

  6. 在controller中将timestamp类型的数据通过toString()方法变成字符串

    然后在miniui里面将dateFormat="yyyy-MM-dd",变成想要的格式.

  7. ES6 系列之 defineProperty 与 proxy

    ,, ; ; ; } ; }); }; ; }); } });

  8. POJ 3140 Contestants Division 【树形DP】

    <题目链接> 题目大意:给你一棵树,让你找一条边,使得该边的两个端点所对应的两颗子树权值和相差最小,求最小的权值差. 解题分析: 比较基础的树形DP. #include <cstdi ...

  9. 动画库NineOldAndroids

    动画库NineOldAndroids   NineOldAndroids组件是一个向下兼容的动画库,主要是使低于API 11的系统也能够使用View的属性动画.该动画库支持旋转.移动.透明渐变.缩放等 ...

  10. 理解Array.prototype.slice.call(arguments)

    在很多时候经常看到Array.prototype.slice.call()方法,比如Array.prototype.slice.call(arguments),下面讲一下其原理: 1.基本讲解 1.在 ...