bootstrap-fileinput组件在完成上传后清空输入框的方法

本文介绍了一种在使用Bootstrap FileInput组件后,如何通过模拟点击文件选择框的移除按钮来清空文件选择框的方法。此方法适用于在表单提交后需要清空文件输入框的场景。

使用bootstrap-fileinput上传组件,在上传文件后,发现没有提供方法可以清空文件选择框,form reset也不行,在网上查了半天也没有找到相关的资料,想到一个变通的方法,就是模拟点击文件选择框的移除按钮,该按钮在选择文件后会出现,并且带有样式fileinput-remove-button,所以可以在表单提交后调用$(".fileinput-remove-button").click();来清空文件选择框。

<!DOCTYPE html> <html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro"> <head> <th:block th:include="include :: header('新增运营资产入库单申请信息')"/> <th:block th:include="include :: bootstrap-fileinput-css" /> <th:block th:include="include :: layui-css" /> </head> <body class="white-bg"> <div class="wrapper wrapper-content animated fadeInRight ibox-content"> <div class="row"> <div class="col-sm-offset-0 col-sm-10" style="margin-left: 20px"> <button type="button" class="btn btn-sm btn-warning" onclick="closePage()"><i class="fa fa-reply-all"></i> <span th:text="#{asset.currency.cancel}">取消</span></button> <button type="button" id="btnTempSave" class="btn btn-sm btn-success" ><i class="fa fa-save"></i> <span th:text="#{asset.currency.TempSave}">暂存</span></button> <button type="button" id="btnSave" class="btn btn-sm btn-primary" ><i class="fa fa-check"></i> <span th:text="#{asset.currency.submit}">提交</span></button>  <!--<button type="button" id="print" class="btn btn-sm btn-success" ><i class="fa fa-print"></i> 打印</button>--> </div> </div> <form class="form-horizontal m" id="form-warehouse-add"> <span id="total" style="display: none"></span> <input name="uuid" th:value="${uuid}" id="uuid" type="hidden"> <input name="itemStatus" th:value="1" id="itemStatus" type="hidden"> <h4 class="form-header h4"><span th:text="#{asset.currency.basicInfo}">基本信息</span></h4> <!-- <label class="col-sm-3 is-required">名称:</label>--> <div class="row" style="margin-left: 25px"> <div class="col-sm-6"> <div class="form-group" > <label class="col-sm-2 control-label is-required" style="text-align: left" th:text="#{asset.currency.name}+':'">名称:</label> <div class="col-sm-8"> <input id="warehouseName" name="warehouseName" class="form-control" type="text" required> </div> </div> </div> <div class="col-sm-6"> <div class="form-group"> <label class="col-sm-3 control-label is-required" th:text="#{asset.warehouse.storageReason}+':'" >入库原因:</label> <div class="col-sm-8"> <!-- <textarea name="remarks" class="form-control"></textarea>--> <!-- <input name="remarks" class="form-control" type="text" required>--> <textarea style="max-width: 100%;min-width: 100%;min-height: 50px" name="remarks" class="form-control" type="text" maxlength="125" ></textarea> </div> </div> </div> </div> <!--<div class="row"> <div class="col-sm-10"> <div class="layui-upload" style="margin-left: 9%"> <button type="button" class="btn btn-sm btn-success" id="testList"><i class="fa fa-plus"></i> 选择多文件</button> <div class="layui-upload-list"> <table class="layui-table"> <thead> <tr><th>文件名</th> <th>大小</th> <th>状态</th> <th>操作</th> </tr></thead> <tbody id="demoList"></tbody> </table> </div> <button type="button" class="layui-btn" style="display: none" id="testListAction">开始上传</button> </div> </div> </div>--> <!-- <%@ include file="/pages/projectManage/equipment/equipmentInfoAdd.jsp" %>--> <!-- <div th:replace="/common/file/fileAdd::html" ></div>--> <iframe style="margin-left: -113px" th:replace="asset/common/file/fileAdd::html"></iframe> <h4 class="form-header h4"><span th:text="#{asset.warehouse.StockInList}">入库清单</span></h4> <h3 class=""><span style="color: red;font-style:italic;font-weight: 600" th:text="#{asset.save.tips}"></span></h3> <div class="row" style="margin-left: 5px"> <div class="col-sm-12 search-collapse" style="display: none"> <form id="formId"> <div class="select-list" > <ul> <li> <label>录入状态:</label> <input type="text" name="assetEntryStatus" id="assetEntryStatus"/> </li> <li> <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i> 搜索</a> <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i> 重置</a> </li> </ul> </div> </form> </div> <div class="col-sm-12" > <div class="btn-group-sm" id="toolbar" role="group"> <a class="btn btn-success" onclick="$.operate.addFull()" shiro:hasPermission="task:escrowTemp:add"> <i class="fa fa-plus"></i> <span th:text="#{asset.currency.add}">添加</span> </a> <!--<a class="btn btn-primary single disabled" onclick="$.operate.editFull()" shiro:hasPermission="task:temp:edit"> <i class="fa fa-edit"></i> 修改 </a>--> <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="task:escrowTemp:remove"> <i class="fa fa-remove"></i> <span th:text="#{asset.currency.remove}">删除</span> </a> <!-- <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="task:temp:export"> <i class="fa fa-download"></i> 导出 </a>--> <!--<a class="btn btn-info" onclick="$.table.importExcel()" shiro:hasPermission="task:temp:import"> <i class="fa fa-upload"></i> 批量导入 </a>--> <a class="btn btn-info" onclick="$.table.importExcel()" > <i class="fa fa-upload"></i> <span th:text="#{asset.currency.batchImport}">批量导入</span> </a> <a class="btn btn-danger" onclick="deleteCursor()" > <i class="fa fa-remove"></i> <span th:text="#{asset.warehouse.empty}">清空临时表数据</span> </a> <p style="float: right">   <a class="btn btn-primary btn-rounded btn-sm" onclick="selectNormalData()" >[[#{asset.currency.normal}]]<span id="normalNum"></span></a> <a class="btn btn-warning btn-rounded btn-sm" onclick="selectAbnormalData()" >[[#{asset.currency.abnormal}]]<span id="abnormalNum"></span></a> </p> </div> <div class="col-sm-12 select-table table-striped" > <table id="bootstrap-table" class="table text-nowrap" ></table> <p th:include="include :: assetsStatistics"></p> </div> </div> </div> </form> </div> <th:block th:include="include :: footer" /> <th:block th:include="include :: bootstrap-fileinput-js" /> <th:block th:include="include :: layui-js" /> <th:block th:include="include :: upload-js" /> <th:block th:include="include :: common-js" /> <th:block th:include="include :: bootstrap-table-fixed-columns-js" /> <script th:inline="javascript"> var prefix = ctx + "task/escrowWarehouse"; var uploadPrefix = ctx + "task/info"; var uuid = $("#uuid").val(); console.log(uuid) var applyId ; //运营资产入库类型为14 var applyType = '14' ; /*入库资产临时清单*/ var editFlag = [[${@permission.hasPermi('task:escrowTemp:edit')}]]; var removeFlag = [[${@permission.hasPermi('task:escrowTemp:remove')}]]; var assetSourceDatas = [[${@dict.getType('asset_source')}]]; var assetStatusDatas = [[${@dict.getType('asset_status')}]]; var assetEntryStatusDatas = [[${@dict.getType('asset_entry_status')}]]; var tempPrefix = ctx + "task/escrowTemp"; var deptName = [[${deptName}]]; //获取应用路径 var ROOT = [[${#servletContext.contextPath}]]; //获取默认语言 var LANG_COUNTRY = [[${#locale.language+'_'+#locale.country}]]; //初始化i18n插件 i18nInitialization(ROOT,LANG_COUNTRY); $(function() { $("#uploadDemo").css("margin-left","37px"); // 为流程申请预设申请名称提示语 $("#warehouseName").val(new Date().getFullYear() + "年" + deptName + "运营资产入库申请"); var options = { url: tempPrefix + "/list", createUrl: tempPrefix + "/add?uuid="+uuid, updateUrl: tempPrefix + "/edit/{id}", removeUrl: tempPrefix + "/remove", exportUrl: tempPrefix + "/export", importUrl: tempPrefix + "/importData?uuid="+uuid, importTemplateUrl: tempPrefix + "/importTemplate", fixedColumns: true, fixedNumber: 2, fixedRightNumber: 2, // pagination: false, modalName: "入库资产清单临时", showPageGo: true, responseHandler: function (res) { setAssetsStatisticsValue(res); selectAssetEntryStatusCount(); }, // responseHandler: function (res) { // console.log(res) // $("#normalNum").html(res.normalNum); // $("#abnormalNum").html(res.abNormalNum); // $("#total").html(res.total); // return res; // }, columns: [{ checkbox: true, }, { field: 'id', /* title: '主键ID',*/ title: i18n('asset.currency.id'), visible: false }, { field: 'assetEntryStatus', /*title: '资产录入状态',*/ title: i18n('asset.currency.assetEntryStatus'), formatter: function(value, row, index) { return $.table.selectDictLabel(assetEntryStatusDatas, value); } }, { /* title: '操作',*/ title: i18n('asset.currency.operation'), align: 'center', formatter: function(value, row, index) { var actions = []; var status = row.assetEntryStatus; actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.editFull(\'' + row.id + '\')"><i class="fa fa-edit"></i>'+[[#{asset.currency.edit}]]+'</a> ');//编辑 actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>'+[[#{asset.currency.remove}]]+'</a> ');//删除 if (status == 0) { actions.push('<a class="btn btn-primary btn-xs " href="javascript:void(0)" onclick="checkStatusDescription(\'' + row.statusDescription + '\')"><i class="fa fa-search"></i>'+[[#{asset.warehouse.checkCause}]]+'</a>');//查看异常原因 } return actions.join(''); } }, { /*field: 'standardAssetVO', title: '资产名称', formatter: function(value, row, index) { if(value!=null) { return value.name; } }*/ field: 'name', /*title: '资产名称',*/ title: i18n('asset.currency.assetName'), }, { /* field: 'supplier', title: '供应商', formatter: function(value, row, index) { if(value != null) { return value.name; } }*/ field: 'supplierName', /* title: '供应商',*/ title: i18n('asset.currency.supplier'), visible: false }, { /*field: 'standardAssetVO', title: '规格型号', formatter: function(value, row, index) { if(value!=null) { return value.model; } }*/ field: 'model', /*title: '规格型号',*/ title: i18n('asset.currency.model'), }, { /*field: 'standardAssetVO', title: '资产大类', formatter: function(value, row, index) { if(value!=null) { return value.parentCategoryName; } }*/ field: 'parentCategoryName', /*title: '资产大类',*/ title: i18n('asset.currency.assetCategories'), visible: false }, { /*field: 'standardAssetVO', title: '资产性质', formatter: function(value, row, index) { if(value!=null) { return value.categoryName; } }*/ field: 'categoryName', /*title: '资产性质',*/ title: i18n('asset.currency.assetNature'), }, { /*field: 'standardAssetVO', title: '资产类型', formatter: function(value, row, index) { if(value!=null) { return value.childCategoryName; } }*/ field: 'childCategoryName', /* title: '资产类型',*/ title: i18n('asset.currency.assetType'), visible: false }, { field: 'assetSource', /*title: '资产来源',*/ title: i18n('asset.currency.assetSource'), formatter: function(value, row, index) { return $.table.selectDictLabel(assetSourceDatas, value); }, visible: false }, // { // field: 'serialNumber', // title: 'SN号' // }, { field: 'purchaseDate', /*title: '购置日期',*/ title: i18n('asset.currency.purchaseDate'), formatter: function(value) { if(value!=null && value!="") { return value.substring(0, 10); } else { return ""; } }, visible: false }, { field: 'serviceLife', /*title: '使用期限',*/ title: i18n('asset.currency.serviceLife'), visible: false }, { /*field: 'userDept', title: '使用部门', formatter: function(value, row, index) { if(value!=null) { return value.name; } }*/ field: 'userDeptName', /*title: '使用部门',*/ title: i18n('asset.currency.userDept') }, { /*field: 'user', title: '使用人员', formatter: function(value, row, index) { if(value!=null) { return value.name; } }*/ field: 'userName', /*title: '使用人员',*/ title: i18n('asset.currency.users') }, { /*field: 'managementDept', title: '管理部门', formatter: function(value, row, index) { if(value!=null) { return value.name; } }*/ field: 'managementDeptName', /*title: '管理部门',*/ title: i18n('asset.currency.managementDept'), visible: false }, { /* field: 'managementPerson', title: '管理部门责任人', formatter: function(value, row, index) { if(value!=null) { return value.name; } }*/ field: 'managementPersonName', /* title: '管理部门责任人',*/ title: i18n('asset.currency.managementPersonName'), visible: false }, { field: 'num', /*title: '数量',*/ title: i18n('asset.currency.quantity'), }, { field: 'unit', /* title: '单位',*/ title: i18n('asset.currency.unit'), }, { field: 'price', /* title: '单价(元)',*/ title: i18n('asset.currency.price'), }, { // title: '总金额', title: i18n('asset.currency.totalPrice'), formatter: function(value, row, index) { return '<span>¥' + amountFmt(row.num * row.price) + '</span>'; }, footerFormatter: function (row) { var sumOriginalValue = 0; var rowSum=0; for (var i in row) { // sumOriginalValue += parseFloat(value[i].originalValue); rowSum = row[i].num * row[i].price sumOriginalValue = accAdd(parseFloat(rowSum),sumOriginalValue) } return '<span style=\"font-weight:normal\">¥' + sumOriginalValue.toFixed(2) + '</span>'; } }, { field: 'warehouseDate', /*title: '入库日期',*/ title: i18n('asset.warehouse.StorageDate'), visible: false }, { /*field: 'standardAssetVO', title: '制造商', formatter: function(value, row, index) { if(value!=null) { return value.manufacturer.name; } }*/ field: 'manufacturerName', /*title: '制造商',*/ title: i18n('asset.currency.manufacturer'), visible: false }, { /*field: 'position', title: '地点', formatter: function(value, row, index) { if(value!=null) { return value.name; } }*/ field: 'positionName', /*title: '地点',*/ title: i18n('asset.currency.place'), visible: false }, { field: "position2", title: i18n('asset.currency.place') + '2', visible: false }, { field: "position3", title: i18n('asset.currency.place') + '3', visible: false }, { field: "position4", title: i18n('asset.currency.place') + '4', visible: false }, // { // field: "position5", // title: i18n('asset.currency.place') + '5', // }, { field: 'assetStatus', /*title: '资产状态',*/ title: i18n('asset.currency.assetStatus'), formatter: function(value, row, index) { return $.table.selectDictLabel(assetStatusDatas, value); }, visible: false }, // { // field: 'mac', // title: 'MAC地址' // }, // { // field: 'financialNumber', // title: '财务编号' // }, { field: 'remarks', title: '备注', title: i18n('asset.currency.remarks'), visible: false } ] }; $.table.init(options); //分页国际化 pageInternationalization(); selectAssetEntryStatusCount(); }); function selectNormalData () { $("#assetEntryStatus").val(1); $.table.search(); } function selectAbnormalData () { $("#assetEntryStatus").val(0); $.table.search(); } //数量统计 function selectAssetEntryStatusCount () { var data = $("#form-warehouse-add").serializeArray(); $.ajax({ type: "post", url: tempPrefix + "/selectAssetEntryStatusCount", dataType: "json", data: data, contentType: "application/x-www-form-urlencoded", success: function (data) { if (data[0] === undefined) { $("#abnormalNum").html("0"); } else { $("#abnormalNum").html(data[0]); } if (data[1] === undefined) { $("#normalNum").html("0"); } else { $("#normalNum").html(data[1]); } } }) } $("#form-warehouse-add").validate({ focusCleanup: true }); //保存 $("#btnSave").click(function () { submitHandler("1"); }); //暂存 $("#btnTempSave").click(function () { submitHandler("0"); }); function submitHandler(status) { if ($.validate.form()) { var abnormalNum = $("#abnormalNum").text(); if(abnormalNum != null && abnormalNum>0 && status=="1"){ $.modal.alert("存在异常数据,请修改后再提交!"); return; } var normalNum = $("#normalNum").text(); if(normalNum < 1 && status=="1"){ $.modal.alert("请添加入库清单再提交!"); return; } var data = $("#form-warehouse-add").serializeArray(); data.push({"name": "status", "value": status}); if(status=="1") { $.modal.confirm("确认要提交数据吗?", function() { addData(); }); } else if(status=="0") { addData(); } function addData() { $.ajax({ type: "post", url: prefix + "/add", // contentType: "application/json;charset=UTF-8", dataType: "json", data: data, beforeSend: function () { $.modal.loading("正在处理中,请稍后..."); }, success: function (data) { applyId = data.data.id ;//赋值 //保存成功后触发文件上传 triggerUploadAdd(); } }) } } } //加载多文件列表 upload(uploadPrefix + "/upload","file",0); //关闭当前tab function closePage() { $.modal.confirm("关闭之后,数据不会保存,确定关闭吗?", function () { $.modal.closeTab(); }); } </script> </body> <!-- 导入区域 --> <script id="importTpl" type="text/template"> <form enctype="multipart/form-data" class="mt20 mb10"> <div class="col-xs-offset-1"> <input type="file" id="file" name="file"/> <div class="mt10 pt5"> <!-- <input type="checkbox" id="updateSupport" name="updateSupport" title="如果编号已经存在,更新这条数据。"> 是否更新已经存在的位置数据--> <a th:onclick="downloadFile([[${downLoadTemplateUrl}]],[[${downLoadTemplateName}]]);" class="btn btn-default btn-xs" style="margin-left: auto"><i class="fa fa-file-excel-o"></i> 下载模板</a> <!-- <a onclick="$.table.importTemplate()" class="btn btn-default btn-xs"><i class="fa fa-file-excel-o"></i> 下载模板</a>--> </div> <font color="red" class="pull-left mt10"> 提示:仅允许导入“xls”或“xlsx”格式文件! </font> </div> </form> </script> </html> 为什么$.operate.addFull()明明没有说明url和参数,他却可以跳转到对应的页面
最新发布
11-12
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值