Home Web Front-end JS Tutorial Complete example of bootstrap fileinput

Complete example of bootstrap fileinput

Feb 24, 2017 pm 05:53 PM

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

bootstrap fileinput完整实例

The versions are all 3.x

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

<!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 = $(&#39;#&#39; + ctrlName);

 

 //初始化上传控件的样式

 control.fileinput({

 language: &#39;zh&#39;, //设置语言

 uploadUrl: uploadUrl, //上传的地址

 allowedFileExtensions: [&#39;jpg&#39;, &#39;gif&#39;, &#39;png&#39;],//接收的文件后缀

 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: &#39;multipart/form-data&#39;,

 validateInitialCount:true,

 previewFileIcon: "<i class=&#39;glyphicon glyphicon-king&#39;></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(&#39;文件格式类型不正确&#39;);

 return;

 }

 //1.初始化表格

 var oTable = new TableInit();

 oTable.Init(data);

 $("#p_startimport").show();

 });

}

 return oFile;

};

</script>

Copy after login

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!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

What should I do if I encounter garbled code printing for front-end thermal paper receipts? What should I do if I encounter garbled code printing for front-end thermal paper receipts? Apr 04, 2025 pm 02:42 PM

Frequently Asked Questions and Solutions for Front-end Thermal Paper Ticket Printing In Front-end Development, Ticket Printing is a common requirement. However, many developers are implementing...

Demystifying JavaScript: What It Does and Why It Matters Demystifying JavaScript: What It Does and Why It Matters Apr 09, 2025 am 12:07 AM

JavaScript is the cornerstone of modern web development, and its main functions include event-driven programming, dynamic content generation and asynchronous programming. 1) Event-driven programming allows web pages to change dynamically according to user operations. 2) Dynamic content generation allows page content to be adjusted according to conditions. 3) Asynchronous programming ensures that the user interface is not blocked. JavaScript is widely used in web interaction, single-page application and server-side development, greatly improving the flexibility of user experience and cross-platform development.

Who gets paid more Python or JavaScript? Who gets paid more Python or JavaScript? Apr 04, 2025 am 12:09 AM

There is no absolute salary for Python and JavaScript developers, depending on skills and industry needs. 1. Python may be paid more in data science and machine learning. 2. JavaScript has great demand in front-end and full-stack development, and its salary is also considerable. 3. Influencing factors include experience, geographical location, company size and specific skills.

Is JavaScript hard to learn? Is JavaScript hard to learn? Apr 03, 2025 am 12:20 AM

Learning JavaScript is not difficult, but it is challenging. 1) Understand basic concepts such as variables, data types, functions, etc. 2) Master asynchronous programming and implement it through event loops. 3) Use DOM operations and Promise to handle asynchronous requests. 4) Avoid common mistakes and use debugging techniques. 5) Optimize performance and follow best practices.

How to merge array elements with the same ID into one object using JavaScript? How to merge array elements with the same ID into one object using JavaScript? Apr 04, 2025 pm 05:09 PM

How to merge array elements with the same ID into one object in JavaScript? When processing data, we often encounter the need to have the same ID...

How to achieve parallax scrolling and element animation effects, like Shiseido's official website?
or:
How can we achieve the animation effect accompanied by page scrolling like Shiseido's official website? How to achieve parallax scrolling and element animation effects, like Shiseido's official website? or: How can we achieve the animation effect accompanied by page scrolling like Shiseido's official website? Apr 04, 2025 pm 05:36 PM

Discussion on the realization of parallax scrolling and element animation effects in this article will explore how to achieve similar to Shiseido official website (https://www.shiseido.co.jp/sb/wonderland/)...

The Evolution of JavaScript: Current Trends and Future Prospects The Evolution of JavaScript: Current Trends and Future Prospects Apr 10, 2025 am 09:33 AM

The latest trends in JavaScript include the rise of TypeScript, the popularity of modern frameworks and libraries, and the application of WebAssembly. Future prospects cover more powerful type systems, the development of server-side JavaScript, the expansion of artificial intelligence and machine learning, and the potential of IoT and edge computing.

The difference in console.log output result: Why are the two calls different? The difference in console.log output result: Why are the two calls different? Apr 04, 2025 pm 05:12 PM

In-depth discussion of the root causes of the difference in console.log output. This article will analyze the differences in the output results of console.log function in a piece of code and explain the reasons behind it. �...

See all articles