头部均为:

<link href="//netdna.bootstrapcdn.com/bootstrap/3.1.0/css/bootstrap.min.css" rel="stylesheet">
<script type='text/javascript' src="//ajax.googleapis.com/ajax/libs/jquery/2.0.2/jquery.min.js"></script>
<script type='text/javascript' src="//netdna.bootstrapcdn.com/bootstrap/3.1.0/js/bootstrap.min.js"></script>

方法一: Input File - Popover Preview Image  原文

HTML

<div class="container"><div class="row">    <div class="col-xs-12 col-md-6 col-md-offset-3 col-sm-8 col-sm-offset-2">  <!-- image-preview-filename input [CUT FROM HERE]--><div class="input-group image-preview"><input type="text" class="form-control image-preview-filename" disabled="disabled"> <!-- don't give a name === doesn't send on POST/GET --><span class="input-group-btn"><!-- image-preview-clear button --><button type="button" class="btn btn-default image-preview-clear" style="display:none;"><span class="glyphicon glyphicon-remove"></span> Clear</button><!-- image-preview-input --><div class="btn btn-default image-preview-input"><span class="glyphicon glyphicon-folder-open"></span><span class="image-preview-input-title">Browse</span><input type="file" accept="image/png, image/jpeg, image/gif" name="input-file-preview"/> <!-- rename it --></div></span></div><!-- /input-group image-preview [TO HERE]--> </div></div>
</div>

CSS

.container{margin-top:20px;
}
.image-preview-input {position: relative;overflow: hidden;margin: 0px;    color: #333;background-color: #fff;border-color: #ccc;
}
.image-preview-input input[type=file] {position: absolute;top: 0;right: 0;margin: 0;padding: 0;font-size: 20px;cursor: pointer;opacity: 0;filter: alpha(opacity=0);
}
.image-preview-input-title {margin-left:2px;
}

JS

$(document).on('click', '#close-preview', function(){ $('.image-preview').popover('hide');// Hover befor close the preview$('.image-preview').hover(function () {$('.image-preview').popover('show');}, function () {$('.image-preview').popover('hide');});
});$(function() {// Create the close buttonvar closebtn = $('<button/>', {type:"button",text: 'x',id: 'close-preview',style: 'font-size: initial;',});closebtn.attr("class","close pull-right");// Set the popover default content$('.image-preview').popover({trigger:'manual',html:true,title: "<strong>Preview</strong>"+$(closebtn)[0].outerHTML,content: "There's no image",placement:'bottom'});// Clear event$('.image-preview-clear').click(function(){$('.image-preview').attr("data-content","").popover('hide');$('.image-preview-filename').val("");$('.image-preview-clear').hide();$('.image-preview-input input:file').val("");$(".image-preview-input-title").text("Browse"); }); // Create the preview image$(".image-preview-input input:file").change(function (){     var img = $('<img/>', {id: 'dynamic',width:250,height:200});      var file = this.files[0];var reader = new FileReader();// Set preview image into the popover data-contentreader.onload = function (e) {$(".image-preview-input-title").text("Change");$(".image-preview-clear").show();$(".image-preview-filename").val(file.name);            img.attr('src', e.target.result);$(".image-preview").attr("data-content",$(img)[0].outerHTML).popover("show");}        reader.readAsDataURL(file);});
});

方法二:Beautiful jQuery File Upload Plugin with Bootstrap  下载

方法三: Image Upload Preview Plugin With jQuery And Bootstrap - img-upload  下载

How to use it:

1. Load Bootstrap's stylesheet and the img-upload.css in the head section of the document.

<link rel="stylesheet" href="bootstrap.min.css">
<link href="css/bootstrap-imgupload.css" rel="stylesheet">

2. Build the html structure for the image uploader ui with a preview area.

<form><div class="form-group"><div class="imgupload panel panel-default"><div class="panel-heading clearfix"><h3 class="panel-title pull-left">Upload image</h3><div class="btn-group pull-right"><button type="button" class="btn btn-default active">File</button><button type="button" class="btn btn-default">URL</button></div></div><div class="file-tab panel-body"><div><button type="button" class="btn btn-default btn-file"><span>Browse</span><input type="file" name="file-input"></button><button type="button" class="btn btn-default">Remove</button></div></div><div class="url-tab panel-body"><div class="input-group"><input type="text" class="form-control" placeholder="Image URL"><div class="input-group-btn"><button type="button" class="btn btn-default">Submit</button></div></div><input type="hidden" name="url-input"></div></div></div>
</form>

3. Load both jQuery library and the jQuery img-upload plugin's script at the end of the document.

<script src="//code.jquery.com/jquery-1.12.2.min.js"></script>
<script src="js/bootstrap-imgupload.js"></script>

4. Call the imgUpload() function to active the plugin.

$('.img-upload').imgupload();

5. Available plugin options.

$('.img-upload').imgupload({allowedFormats: [ "jpg", "jpeg", "png", "gif" ],previewWidth: 250,previewHeight: 250,maxFileSizeKb: 2048
});

方法四: bootstrap-fileinput   DEMO  下载

An enhanced HTML 5 file input for Bootstrap 3.x with file preview, multiple selection, and more features.

Usage

Step 1: Load the following assets in your header.

<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet">
<link href="path/to/css/fileinput.min.css" media="all" rel="stylesheet" type="text/css" />
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.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="path/to/js/plugins/canvas-to-blob.min.js" type="text/javascript"></script>
<script src="path/to/js/fileinput.min.js"></script>
<!-- bootstrap.js below is only needed if you wish to the feature of viewing detailsof 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="path/to/js/fileinput_locale_<lang>.js"></script>

If you noticed, you need to load the jquery.min.js and bootstrap.min.css in addition to the fileinput.min.css and fileinput.min.js. The locale file fileinput_locale_<lang>.js can be optionally included for translating for your language if needed.

NOTE: The canvas-to-blob.min.js file is the source for the JavaScript-Canvas-to-Blob plugin by blueimp. It is required to be loaded before fileinput.js if you wish to use the image resize feature of the bootstrap-fileinput plugin. For ease of access, the plugin source for JavaScript-Canvas-to-Blob is included in the js/plugins folder of this project repository.

Step 2: Initialize the plugin on your page. For example,

// initialize with defaults
$("#input-id").fileinput();// with plugin options
$("#input-id").fileinput({'showUpload':false, 'previewFileType':'any'});

The #input-id is the identifier for the input (e.g. type = file) on your page, which is hidden automatically by the plugin.

Alternatively, you can directly call the plugin options by setting data attributes to your input field.

<input id="input-id" type="file" class="file" data-preview-file-type="text" >

原文/转自: Bootstrap 3 : 图片上传预览 image upload preview

Bootstrap 3 : 图片上传预览 image upload preview相关推荐

  1. java 图片上传 预览 demo_图片上传预览

    [实例简介] 实现图片上传预览,可以增加新的空数组,并上传和替换.还有删除功能:提交的时候,还可以判断是否有空的img [实例截图] [核心代码] 613ddc50-96b8-4197-ba2e-1e ...

  2. Angular6自定义指令实现多图片上传预览

    在做移动端开发多时候经常会遇到用户图片上传的需求,有单图片上传预览的需求,也有多图片上传预览的需求.自己刚遇到这个需求的时候有踩到各种个样到坑.经过多番尝试,下面将本人成功的一个案例分享出来(公司对外 ...

  3. php 图片上传预览(转)

    网上找的图片上传预览: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http:/ ...

  4. js实现图片上传预览及进度条

    js实现图片上传预览及进度条 原文js实现图片上传预览及进度条 最近在做图片上传的时候,由于产品设计的比较fashion,上网找了比较久还没有现成的,因此自己做了一个,实现的功能如下: 1:去除浏览器 ...

  5. JAVA实现一个图片上传预览功能

    这个小项目主要使用java实现了一个简单的图片上传预览功能,废话不多说,先上实现成果 ^ _ ^

  6. JavaScript 图片上传预览效果

    图片上传预览是一种在图片上传之前对图片进行本地预览的技术. 使用户选择图片后能立即查看图片,而不需上传服务器,提高用户体验. 但随着浏览器安全性的提高,要实现图片上传预览也越来越困难. 不过群众的智慧 ...

  7. ASP.NET工作笔记之一:图片上传预览及无刷新上传

    转自:http://www.cnblogs.com/sibiyellow/archive/2012/04/27/jqueryformjs.html 最近项目里面涉及到无刷新上传图片的功能,其实也就是上 ...

  8. 模拟QQ心情图片上传预览

    出于安全性能的考虑,目前js端不支持获取本地图片进行预览,正好在做一款类似于QQ心情的发布框,找了不少jquery插件,没几个能满足需求,因此自己使用SWFuplad来实现这个图片上传预览. 先粘上以 ...

  9. js实现图片上传预览功能

    js实现图片上传预览功能 很多业务场景下,我们需要在用户上传图片前,先预览待上传的图片 <body><input type="file"><img s ...

最新文章

  1. JavaScript关键字this指向
  2. Python生成随机五位数——模仿手机验证码
  3. other than ,more than,less than,rather than到底有什么区别
  4. J2ME手机游戏引擎程序结构简述
  5. matlab lu分解 l不是下三角,在MATLAB中执行LU分解而不进行旋转
  6. 旅游网站的主页代码_山西太原网站SEO优化推广联系电话
  7. 《金色梦乡》金句摘抄(五)
  8. JDBC预处理对象prepareStatement
  9. Java基础(三)对象与类
  10. “我要彻底放弃 Debian 操作系统!”
  11. C99标准的新特性(相对于Ansi C)
  12. 语文招教考试-古今中外神话故事汇总,教育心理学知识点
  13. 驾驶员监控系统(DMS)
  14. C-V2X仿真测试之虚拟场景设计
  15. jquery插件 邮箱后缀自动匹配 可自定义
  16. 〖每天学点管理〗——GTD时间管理
  17. excel中如何冻结前三行或者其他行
  18. Python入门习题大全——词汇表
  19. 蒲公英 · JELLY技术周刊 Vol.29: 前端智能化在阿里的那些事
  20. python 股票交易接口 github_GitHub - Higgsbit/vnpy: 基于python的开源交易平台开发框架...

热门文章

  1. 图论 —— 网络流 —— 基本概念与建模技巧
  2. 装箱问题(信息学奥赛一本通-T1226)
  3. 判断整除(信息学奥赛一本通-T1195)
  4. 判决素数个数(信息学奥赛一本通-T1409)
  5. 33 CO配置-控制-产品成本控制-成本对象控制-期末结算-定义每一工厂的差异码
  6. 8 SAP QUERY定制报表操作手册 SQVI-推荐
  7. 4.4.2 数值处理
  8. pandas的自带数据集_用Python和Pandas进行数据清理:检测丢失值
  9. 如何在驱动代码中中/dev目录内自动创建
  10. OpenVINO InferenceEngine 之Grap file