【问题标题】:Insert path of uploaded file in text input field [duplicate]在文本输入字段中插入上传文件的路径[重复]
【发布时间】:2016-01-28 22:36:58
【问题描述】:

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

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

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

【问题讨论】:

  • 请注意,出于安全原因,某些浏览器可能会阻止访问。同样,在服务器上,当您获取文件名路径的文件部分时,文件名可能是假的。因此,为什么要文件名?

标签: javascript jquery


【解决方案1】:

是的,您可以在输入文件上使用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">

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-01-03
    • 2021-08-03
    • 2012-12-17
    • 2011-04-11
    • 2020-01-07
    • 2014-07-26
    • 2020-07-13
    • 2020-12-29
    相关资源
    最近更新 更多