bootstrap中好看的⽂件上传样式(持续更新中)⼀直接使⽤bootstrap,利⽤简单的js控制
⾮常简单,代码如下:
<input id="lefile" type="file" >
<div class="input-append">
<input id="photoCover" class="input-large" type="text" >
好看的qq留言
<a class="btn" οnclick="$('input[id=lefile]').click();">Browse</a>
</div>
<script type="text/javascript">
$('input[id=lefile]').change(function() {
$('#photoCover').val($(this).val());
});
</script>
效果如下:
不需要任何其他的js和css,只需要引⼊bootstrap和jquery即可
其实这个就是拼接出来的,然后js控制显⽰⽂件名。
效果如下:
⼆  bootstrap-filestyle
注意:此样式只能使⽤bootstrap2的css,版本为bootstrap3的css是不兼容的!!(我就因为这个测试了⽼半天。。摔效果如下:
三 bootstrap-file-input
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>bootstrap.file-input</title>
<link href="css/bootstrap.min.css" rel="stylesheet" />
<script type="text/javascript" src="js/jquery-2.0.3.min.js"></script>
<script type="text/javascript" src="js/bootstrap.min.js"></script>
<script type="text/javascript" src="js/bootstrap.file-input.js"></script>
</head>
<body>
<!-- Change the wording using a title tag -->
<input type="file" title="Search for a file to add 1" class="btn-primary">
<br>
<br>
<input type="file" title="Search for a file to add 2" class="btn btn-primary">
<br>
<br>
<input type="file" title="Search for a file to add 3" class="btn-primary">
<br>
<br>
<input type="file" title="Search for a file to add 4" class="btn-primary">
<br>
<br>
<br>
<br>
<br>
Disable the styling:
<!-- Disable the styling -->
<input type="file" data-bfi-disabled>
<script type="text/javascript">
$('input[type=file]').bootstrapFileInput();
</script>
</body>
</html>
引⼊了bootstrap.file-input.js但是直接引⼊有点⼩问题,说不到bootstrapFileInput这个⽅法。于是我就改了⼀点js:
/*
Bootstrap - File Input
======================
This is meant to convert all file input tags into a set of elements that displays consistently in all browsers.
Converts all
<input type="file">
into Bootstrap buttons
<a class="btn">Browse</a>
*/
$.fn.bootstrapFileInput = function() {
这⾥我直接⽤这个⽅法,把前⾯⼀⾏删掉就可以了
this.each(function(i,elem){
.........中间省略
// Add the styles before the first stylesheet
// This ensures they can be easily overridden with developer styles
var cssHtml = '<style>'+
'.file-input-wrapper { overflow: hidden; position: relative; cursor: pointer; z-index: 1; }'+
'.file-input-wrapper input[type=file], .file-input-wrapper input[type=file]:focus, .file-input-wrapper input[type=file]:hover { position: absolute; top: 0; left: 0; cursor: po  '.file-input-name { margin-left: 8px; }'+
'</style>';
$('link[rel=stylesheet]').eq(0).before(cssHtml);
};
好了,到了看效果的时候啦~~
四  Fine Uploader
在官⽹下载是收费的。。我在github下载了⼀个。
下载解压后是这样的:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>bootstrap.file-input</title>
<link href="css/bootstrap.min.css" rel="stylesheet" />
<link href="css/fineuploader.css" rel="stylesheet" />
<script type="text/javascript" src="js/jquery-2.0.3.min.js"></script>
<script type="text/javascript" src="js/bootstrap.min.js"></script>
<script type="text/javascript" src="js/all.fineuploader-4.3.1.min.js"></script>    </head>
<body>
<br>
<div id="manual-fine-uploader"></div>
<div id="triggerUpload" class="btn btn-primary" >
<i class="icon-upload icon-white"></i> Upload now
</div>
<script>
$(document).ready(function() {
var manualuploader = $('#manual-fine-uploader').fineUploader({
request: {
endpoint: 'server/handleUploads'
},
autoUpload: false,
text: {
uploadButton: '<i class="icon-plus icon-white"></i> Select Files'
}
});
$('#triggerUpload').click(function() {
manualuploader.fineUploader('uploadStoredFiles');
});
});
</script>