上传前以html输入显示所选文件 [英] Display selected file in html input before upload
本文介绍了上传前以html输入显示所选文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何显示通过浏览字段选择的文件到html输入中?我想查看按上传之前选择的文件吗?
How can i show file that i select thru browse field into html input? I want to see file that i selected before i press upload?
这是我的代码:
<input id="uploadFile" name="uploadFileOne" type="text" disabled="disabled" value="<?php echo $file_name; ?>" placeholder="EWIS" class="name-info-form file-witdth" />
<input class="upload" type="file" id="uploadOne" name="uploadOne" value="Select File"/ >
推荐答案
<form>
<input class="upload" type="file" id="uploadOne" name="uploadOne" onchange="setfilename(this.value);" value="Select File"/ >
<input id="uploadFile" name="uploadFileOne" type="text" disabled="disabled" placeholder="EWIS" class="name-info-form file-witdth" />
</form>
删除value=<?php echo $file_name; ?>
并使用javascript在文本框中设置文件名
remove value=<?php echo $file_name; ?>
and use the javascript for set the name of file in textbox
<script>
function setfilename(val)
{
var fileName = val.substr(val.lastIndexOf("\\")+1, val.length);
document.getElementById("uploadFile").value = fileName;
}
</script>
使用浏览按钮选择文件时,会触发onchange事件并在文本框中设置文件名:)
when you select the file using browse button, onchange event will fire and set the file name in text-box :)
这篇关于上传前以html输入显示所选文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文