Home >Web Front-end >JS Tutorial >Complete example of bootstrap fileinput
This article introduces how to use bootstrap fileinput.js. The file input plug-in is so powerful and the style is very beautiful. It also supports uploaded file preview, ajax synchronous or asynchronous upload, drag and drop file upload and other cool functions. It is the best file to use. Upload the component.
Folder structure
The versions are all 3.x
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title> New Document </title> <meta name="Generator" content="EditPlus"> <meta name="Author" content=""> <meta name="Keywords" content=""> <meta name="Description" content=""> <link href="bootstrap-3.3.5/dist/css/bootstrap.min.css" rel="stylesheet"> <link href="bootstrap-fileinput-master/css/fileinput.min.css" media="all" rel="stylesheet" type="text/css" /> <script src="jquery-2.1.1.min.js"></script>x <script src="bootstrap-fileinput-master/js/plugins/canvas-to-blob.min.js" type="text/javascript"></script> <script src="bootstrap-fileinput-master/js/fileinput.min.js"></script> <script src="bootstrap-3.3.5/dist/js/bootstrap.min.js" type="text/javascript"></script> <script src="bootstrap-fileinput-master/js/fileinput_locale_zh.js"></script> </head> <body> <form> <p class="" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"> <p class="modal-dialog modal-lg" role="document"> <p class="modal-content"> <p class="modal-header"> <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button> <h4 class="modal-title" id="myModalLabel">请选择Excel文件</h4> </p> <p class="modal-body"> <a href="~/Data/ExcelTemplate/Order.xlsx" class="form-control" style="border:none;">下载导入模板</a> <input type="file" name="txt_file" id="txt_file" multiple class="file-loading" /> </p></p> </p> </p> </form> </body> </html> <script> $(function () { //0.初始化fileinput var oFileInput = new FileInput(); oFileInput.Init("txt_file", "/api/OrderApi/ImportOrder"); }); //初始化fileinput var FileInput = function () { var oFile = new Object(); //初始化fileinput控件(第一次初始化) oFile.Init = function(ctrlName, uploadUrl) { var control = $('#' + ctrlName); //初始化上传控件的样式 control.fileinput({ language: 'zh', //设置语言 uploadUrl: uploadUrl, //上传的地址 allowedFileExtensions: ['jpg', 'gif', 'png'],//接收的文件后缀 showUpload: true, //是否显示上传按钮 showCaption: false,//是否显示标题 browseClass: "btn btn-primary", //按钮样式 //dropZoneEnabled: false,//是否显示拖拽区域 //minImageWidth: 50, //图片的最小宽度 //minImageHeight: 50,//图片的最小高度 //maxImageWidth: 1000,//图片的最大宽度 //maxImageHeight: 1000,//图片的最大高度 //maxFileSize: 0,//单位为kb,如果为0表示不限制文件大小 //minFileCount: 0, maxFileCount: 10, //表示允许同时上传的最大文件个数 enctype: 'multipart/form-data', validateInitialCount:true, previewFileIcon: "<i class='glyphicon glyphicon-king'></i>", msgFilesTooMany: "选择上传的文件数量({n}) 超过允许的最大数值{m}!", }); //导入文件上传完成之后的事件 $("#txt_file").on("fileuploaded", function (event, data, previewId, index) { $("#myModal").modal("hide"); var data = data.response.lstOrderImport; if (data == undefined) { toastr.error('文件格式类型不正确'); return; } //1.初始化表格 var oTable = new TableInit(); oTable.Init(data); $("#p_startimport").show(); }); } return oFile; }; </script>
Knowledge can only be spread by sharing, new knowledge can be promoted, and more can be learned. Every text/blog written here is basically based on searching the information on the Internet and then recording it, and some of it is copied from the original version. I came here and sometimes added some of my own ideas, I hope you all like it.
The above is the entire content of this article. I hope it will be helpful to everyone's learning. I also hope that everyone will support the PHP Chinese website.
For more articles related to bootstrap fileinput complete examples, please pay attention to the PHP Chinese website!