对输入类型=“文件”进行样式化。如何显示文件路径? [英] Styling the input type="file". How do i display the filepath?

查看:137
本文介绍了对输入类型=“文件”进行样式化。如何显示文件路径?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试设置一个input type =file字段的样式。
我的按钮是样式,但我不能找出如何获取文件路径/文件显示时,用户选择要上传的文件。
任何人都可以帮助吗?

I have been trying to style an input type="file" field. My button is styled but i cant seem to figure out how to get the filepath/file to show when the user selects the file to upload. Can anyone out there help ?

    <form action="" method="POST" enctype="multipart/form-data">
    <div class="fileupload-buttonbar">
        <label class="file-upload"><span>Upload....</span><input name="uploadfile" type="file"> </label>    
    </div>
</form>

CSS ...

.file-upload {
overflow: hidden;
display: inline-block;
position: relative;    
vertical-align: middle;
text-align: center;
color: #fff;
border: 2px solid #707070;
background: #A0A0A0;
-moz-border-radius: 8px;
-webkit-border-radius: 8px;
border-radius: 8px;
text-shadow: #000 1px 1px 4px;
cursor:pointer;
}
.file-upload:hover {
background: #2FA2FF;
}
.file-upload.focus {
outline: 2px solid yellow;
}
.file-upload input {
position: absolute;
top: 0;
left: 0;
margin: 0;
font-size: 12px;
opacity: 0;
filter: alpha(opacity=0);
z-index:-1;
}
.file-upload span {
position: absolute;
top: 0;
left: 0;
display: inline-block;
padding-top: .45em;
}
.file-upload { height: 38px; }
.file-upload,
.file-upload span { width: 160px; }    
.file-upload-status {
margin-left: 10px;
vertical-align: middle;
padding: 7px 11px;
font-weight: bold;    
font-size: 16px;
color: #888;
background: #f8f8f8;
border: 3px solid #ddd;
}

我的代码在这里
http://jsfiddle.net/hjNEC/
谢谢这么多:D

My code is here http://jsfiddle.net/hjNEC/ Thank you ever so much :D

推荐答案

向输入添加更改字段,然后只是得到 .value

Add a change event to the input field, and then just get it's .value.

示例(使用jQuery):

Example (using jQuery):

$('input[name="uploadfile"]').change(function(){
    var fileName = $(this).val();
    alert(fileName);
});

演示: http://jsfiddle.net/hjNEC/2/

编辑:由于输入栏位已隐藏,而档案name是其中的一部分,您必须自己在页面上显示 fileName

EDIT: Since the input field is hidden, and the file name is part of that, you're gonna have to display fileName on the page yourself.

这篇关于对输入类型=“文件”进行样式化。如何显示文件路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆