如何将浏览按钮重命名为"选择文件"?例如:
<input type=file name=browse >
如何将浏览按钮重命名为"选择文件"?例如:
<input type=file name=browse >
<script language="JavaScript" type="text/javascript">
function HandleBrowseClick()
{
var fileinput = document.getElementById("browse");
fileinput.click();
}
function Handlechange()
{
var fileinput = document.getElementById("browse");
var textinput = document.getElementById("filename");
textinput.value = fileinput.value;
}
</script>
<input type="file" id="browse" name="fileupload" style="display: none" onChange="Handlechange();"/>
<input type="text" id="filename" readonly="true"/>
<input type="button" value="Click to select file" id="fakeBrowse" onclick="HandleBrowseClick();"/>
group_id
,会发生什么。我应该如何发送它?在HTML中使用<input type="hidden" class="hide" id="group_id" name="group_id" value="2" />
,但在脚本中呢? - Claudio<input type="file">
用 <label>
标签包裹;<span>
或 <a>
;display: none
使 input[type="file"]
不可见。<script language="JavaScript" type="text/javascript">
function HandleBrowseClick()
{
var fileinput = document.getElementById("browse");
fileinput.click();
var textinput = document.getElementById("filename");
textinput.value = fileinput.value;
}
</script>
<input type="file" id="browse" name="fileupload" style="display: none"/>
<input type="text" id="filename" readonly="true"/>
<input type="button" value="Click to select file" id="fakeBrowse" onclick="HandleBrowseClick();"/>
虽然不是最美观的解决方案,但它确实有效。
以下是最佳、简单、短小精悍、没有使用JQuery的纯HTML和JavaScript“重命名”带有文件类型的文本输入框的方法:
<input id='browse' type='file' style='width:0px'>
<button id='browser' onclick='browse.click()'>
*The text you want*
</button>
<input type="file"/>
<button>Open</button>
input { display: none }
jQuery
$( 'button' ).click( function(e) {
e.preventDefault(); // prevents submitting
$( 'input' ).trigger( 'click' );
} );
type="button"
,否则它会提交表单。 - Mihai不,您无法更改文件上传输入的文本。但是有一些技巧可以在按钮上叠加图像。