文件选择域
<input ty PE ="file"> &nbs p; 也是 CSS 啃不动的 一块 骨头,如果实在看不惯原生的样式,一般的做法是把文件选择域设为透明那个,覆盖在其他元素。
<div class=" am -form-group am-form-file">
<button type="button" class="am- BT n am-btn-default am-btn -s m">
<i class="am -i con-cloud-upload"></i> 选择要上传的文件</button>
<input type="file" multiple>
</div>
< hr />
<div class="am-form-group am-form-file">
<i class="am-icon-cloud-upload"></i> 选择要上传的文件
<input type="file" multiple>
</div>
效果如下
但是 官方 给的 方案 一个问题在于,上 传文件 之后图标没有 改变 ,也没有显示上传文件名的地方。
于是我做了一个小小的修改:加入一段js代码
$('input[type="file"]').change(function (event) {
VAR t hat = this;
var file = $(that)[0].files[0];
if(file){
$(that).p rev ().text(that.files[0].name);
$(that).attr({ 'src': window.URL.createObjectURL(that.files[0]) });
}
});
上传文件后
进一步的,如果传的是图片,我想预览上传的图片效果图呢。
那就再加一段小代码:
$('input[type="file"]').closest('div').hover(function(){
if($(this).find('input[type="file"]').attr('src')){
$('body').append('<div class=" img View" style="width: '+$(this).find('button').css('width')+';top: '+($(this).find('button').offset().top-210)+'px;left: '+$(this).find('button').offset().left+'px;h ei ght: 200px;pos IT ion: absolute;text-align: center ;line-height: 200px;z-index: 99999;background-color: rgba(51, 51, 51,0.6);"><img style=" ;m ax-width: 90%;max-height: 90%;" src="'+$(this).find('input[type="file"]').attr('src')+'"></div>')
}
},function(){
$('.imgView').remove();
});
当鼠标放上面就会自动显示上传图片的缩略图了。
转载 于:https://my.oschina.net/u/3463305/ blog /1504565
总结
到此这篇关于Amaze UI 文件选择域的示例代码的 文章 就介绍到这了,更多相关Amaze UI 文件选择域内容请搜索以前的文章或继续浏览下面的相关文章,希望大家以后多多支持!
总结
以上是 为你收集整理的 Amaze UI 文件选择域的示例代码 全部内容,希望文章能够帮你解决 Amaze UI 文件选择域的示例代码 所遇到的问题。
如果觉得 网站内容还不错, 推荐好友。
查看更多关于Amaze UI 文件选择域的示例代码的详细内容...
声明:本文来自网络,不代表【好得很程序员自学网】立场,转载请注明出处:http://haodehen.cn/did206090