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

Insert path of uploaded file in text input field

本文关键字:文件 路径 插入 文本 输入 字段      更新时间:2023-09-26

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

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

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

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

$('input[type="file"]').change(function(){
     $('input[type="text"]').val( $(this).val() );
})
<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">