-4
我的问题是当用户选择一个文件时,文件名应该出现在文本字段上。请告诉我这是怎么做的? 如何在<input type =“text”>标签内放置<input type =“file”>?
我的问题是当用户选择一个文件时,文件名应该出现在文本字段上。请告诉我这是怎么做的? 如何在<input type =“text”>标签内放置<input type =“file”>?
您的HTML
<input type="file" id = "file_upload" />
<input id="file_name" type="text" />
您的JavaScript
document.getElementById('file_upload').onchange = file_name;
function file_name() {
var filename = this.value;
var lastIndex = filename.lastIndexOf("\\");
if (lastIndex >= 0) {
filename = filename.substring(lastIndex + 1);
}
document.getElementById('file_name').value = filename;
}
谢谢@ chetan paliwal – 2013-02-13 06:57:10
– 2013-02-13 06:09:19
内的另一个输入将无法工作。出于安全原因,文件输入无法在文件选择之前显示设置的“默认”值。你需要从盒子中思考并用JS来“伪造”情况。 – 2013-02-13 06:27:16