【发布时间】:2011-08-31 14:21:39
【问题描述】:
【问题讨论】:
-
将其添加到输入中似乎在 webkit 中有效.... style="width: 80px; height: 25px; overflow: hidden;"
标签: javascript html
【问题讨论】:
标签: javascript html
input[type='file'] {
color: transparent;
}
享受
【讨论】:
没有跨浏览器的方法可以做到这一点。 “未选择文件”文本位于小部件的实现定义部分中,我不相信大多数浏览器都提供了太多特定于浏览器的自定义方式。另一方面,当 value 属性为空时,您可以简单地使用 CSS 来覆盖文本。
【讨论】:
您可以通过定义输入的宽度并隐藏超出的内容(不需要的“未选择文件”文本)来做到这一点。
input {
width: 132px;
overflow:hidden;
}
Here is the demonstration on jsfiddle.
注意:每种语言都有自己的默认文本,并且可能呈现不同的输入大小。 In brazilian portuguese 132px 的宽度就好了!
【讨论】:
您可以将文件字段替换为带有此问题答案的按钮:file upload button without input field?
【讨论】:
CSS
<style>
#image_file{
position: relative;
width: 188px;
border: 1px solid #BBB;
margin: 1px;
cursor: pointer;
float: left;
}
</style>
HTML
<input id="image_file" onclick="getFile()" onfocus="this.blur()" value=""/>
<div style='height: 0px;width: 0px; overflow:hidden;'>
<input type="file" id="PinSpot_file">
</div>
<input type="button" onclick="getFile()" style="background-color: #DDD;" value="Browser" >
JAVASCRIPT
function getFile(){
document.getElementById("PinSpot_file").click();
}
// Event when change fields
$('#PinSpot_file').live('change', function(e) {
var file = this.value;
var fileName = file.split("\\");
document.getElementById("image_file").value = fileName[fileName.length-1];
//AJAX
}
【讨论】:
这是一个非常好的 hack,而且更干净。
HTML
<div id="file_info' style='display:inline;'>Browse</div>
<input type="file" name='file[]' multiple style='opacity: 0;' onchange='displayFileName()'/>
JS
function displayFileName() {
var files = $('input[type="file"]')[0].files;
document.getElementById('file_info').innerHTML = files.length + " images to upload";`
}
【讨论】:
好吧,由于没有办法完全禁用文本,我建议要么在文本上放置一个元素,要么尝试以下解决方案..
CSS
input[type="file"] {
width: 90px; /* Keep it under 100px in order to hide the unwanted text. */
}
并为元素添加一个 html inline-title 属性以隐藏“未选择文件”悬停文本。
HTML
<input type="file" id="FileId" title="">
或者,您可以使用 JavaScript 完成所有操作。
JS
document.addEventListener('DOMContentLoad', myFunction);
function myFunction() {
const FilePicker = document.getElementById('FileId');
FilePicker.style.width = "90px";
FilePicker.title = ""; // Leave This Empty
}
【讨论】:
你可以试试这个。它适用于我的火狐浏览器
<style type="">
input[type='file'] {
color: transparent;
}
</style>
【讨论】: