bootstrap-fileupload-上传文件控件

官方github:https://github.com/kartik-v/bootstrap-fileinput

官方dome网站:http://plugins.krajee.com/file-basic-usage-demo

博客参考:http://www.cnblogs.com/wuhuacong/p/4774396.html

 

如何下位案例:其中bootstrap为3.3.5,jquery为2.1.1,bootstrap-fileinput为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="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet">
<link href="bootstrap-fileinput-master/css/fileinput.min.css" media="all" rel="stylesheet" type="text/css" />
<script src="http://code.jquery.com/jquery-2.1.1.min.js"></script>
<!-- canvas-to-blob.min.js is only needed if you wish to resize images before upload.
     This must be loaded before fileinput.min.js -->
<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>
<!-- bootstrap.js below is only needed if you wish to the feature of viewing details
     of text file preview via modal dialog -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js" type="text/javascript"></script>
<!-- optionally if you need translation for your language then include 
    locale file as mentioned below -->
<script src="bootstrap-fileinput-master/js/fileinput_locale_zh.js"></script>
 </head>

 <body>
  <label class="control-label">Select File</label>
<input id="input-1" type="file" class="file">

<label class="control-label">Select File</label>
<input id="input-1a" type="file" class="file" data-show-preview="false">

<label class="control-label">Select File</label>
<input id="input-2" name="input2[]" type="file" class="file" multiple data-show-upload="false" data-show-caption="true">

<label class="control-label">Readonly Input</label>
<input id="input-3a" type="file" class="file" readonly="true">
<label class="control-label">Disabled Input</label>
<input id="input-3b" type="file" class="file" disabled="true">


<label class="control-label">Select File</label>
<input id="input-4" name="input4[]" type="file" multiple class="file-loading">
<script>
$(document).on('ready', function() {
    $("#input-4").fileinput({showCaption: false});
});
</script>


<label class="control-label">Select File</label>
<input id="input-6" name="input6[]" type="file" multiple class="file-loading">
<script>
$(document).on('ready', function() {
    $("#input-6").fileinput({
        showUpload: false,
        maxFileCount: 10,
        mainClass: "input-group-lg"
    });
});
</script>


<label class="control-label">Select File</label>
<input id="input-7" name="input7[]" multiple type="file" class="file file-loading" data-allowed-file-extensions='["csv", "txt"]'>
 </body>
</html>

 

转载于:https://www.cnblogs.com/hwaggLee/p/5137858.html

若依(Jui)是基于Bootstrap框架的前端UI库,而Bootstrap-table是一个用于显示数据表格的插件。如果想要在Bootstrap-table中实现多张图片的预览,你可以使用插件如Bootstrap-fileinput或图片懒加载(lazy loading)技术结合。 以下是基本步骤: 1. 首先,引入Bootstrap-table和所需的图片预览插件库,比如Bootstrap-fileinput: ```html <link rel="stylesheet" href="https://cdn.bootcdn.net/ajax/libs/bootstrap-fileinput/5.3.1/css/fileinput.min.css"> <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.min.js"></script> <script src="https://cdn.bootcdn.net/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script> <script src="https://cdn.bootcdn.net/ajax/libs/bootstrap/5.1.3/js/bootstrap.min.js"></script> <script src="https://cdn.jsdelivr.net/npm/bootstrap-fileinput@5.3.1/dist/js/fileinput.min.js"></script> ``` 2. 在HTML结构中,为每个图片字段添加`data-file-input`属性来启用预览功能: ```html <table id="myTable" data-pagination="true" data-height="400"> <thead> <!-- ... --> </thead> <tbody> <tr> <td data-field="image" data-events="fileupload" data-url="api/upload-image">上传图片</td> <!-- 使用插件提供的控件,如:<input type="hidden" name="file" value=""> --> </tr> <!-- ... --> </tbody> </table> ``` 3. 使用Bootstrap-fileinput的JavaScript初始化表格和图片预览: ```javascript $('#myTable').bootstrapTable({ // ...其他配置 events: { 'click .fileinput': function(e, val) { $(this).fileinput('upload'); }, 'fileupload.bs.fileinput': function(e, file, previewId, index) { // 图片上传成功后,替换隐藏域的值并更新显示 $('#myTable').find('[data-field=image]').val(file.url); } } }); ``` 4. 为了实现图片预览,你可能还需要编写一个服务器端处理程序(例如API),返回文件的缩略图或者链接,然后在前端展示图片。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值