我有这个文件输入:
<input id="some_file_input" type="file" name="some_file" class="custom-input-thing" data-buttonName="btn-primary" data-icon="true">
我隐藏了按钮附带的文字,即“没有文件被选中”的文字,只是因为“看起来”:
input[type=file] {
color: transparent;
display: block;
}
当用户选择要上传的文件时,有没有办法更改文件输入的文本?
提前感谢您的帮助。
答案 0 :(得分:1)
使用inputFileText
插件进行此
https://github.com/datchung/jquery.inputFileText
在jQuery之后加载此文件
<script src='jquery-input-file-text.js'></script>
这是你的jQuery代码。
$("input[type=file]").on("change", function() {
$(this).inputFileText( { text: 'Uploaded' } );
});
如果文件已更新,则input[type=file]
的值将会更改。我们使用change
事件处理程序。然后我们包含用于更改文本的插件函数。