更改在jsp文件字段中按文件名选择文件文本

时间:2014-04-18 07:15:20

标签: html jsp

我有文件字段在页面demo.jsp中上传文件(pdf),现在我想当用户要编辑此页面时说demo.jsp,之前上传的文件名将填入文件字段而不是“选择文件” ”

1 个答案:

答案 0 :(得分:0)

您可以尝试这样的事情(解决

<input type="text" id="fileName" readonly="readonly" >
</br>
<small>Here change this with whatever dynamically</small>
</br>
<div class="file_input_div" style="display: inline;">
<input type="button" id="button" value="Open"/>
<input type="file"  style="opacity:0; position:relative; left:-40px;"  onchange="javascript: document.getElementById ('fileName').value = this.value"/>
</div>

DEMO

修改2

<small id='fileName'>Here change this with whatever dynamically</small>
</br>
<div class="file_input_div" style="display: inline;">
<input type="button" id="button" value="Open"/>
<input type="file"  style="opacity:0; position:relative; left:-40px;"  onchange="javascript: document.getElementById('fileName').innerHTML = this.value"/>
</div>

DEMO 2