在文本输入字段中插入上传文件的路径

时间:2016-01-28 22:36:59

标签: javascript jquery

有没有办法在文件被选中到文本输入字段后插入文件的路径?

Select images: <input type="file">
File path here: <input type="text">

我做了一个小例子:https://jsfiddle.net/5by18xon/

1 个答案:

答案 0 :(得分:0)

是的,您可以在输入文件中使用change事件:

&#13;
&#13;
$('input[type="file"]').change(function(){
     $('input[type="text"]').val( $(this).val() );
})
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
Select images: <input type="file"><br><br>
File path here: <input type="text">
&#13;
&#13;
&#13;