gpt4 book ai didi

javascript - 触发点击输入文件

转载 作者:可可西里 更新时间:2023-11-01 02:51:39 24 4
gpt4 key购买 nike

我有这个标记

<div id="wrapper">
<input type="file" id="file" accept="image/*" capture="camera">
<a href="#" id="capture">Submit Cleanup</a>
</div>

和jQuery如下

jQuery(function($){
$('#capture').on('click', function(e){
e.preventDefault();
$('#file').trigger('click');
});
});

该脚本在 PC 浏览器上按预期工作,但当我在移动设备上尝试时,相机没有提示。我也已经尝试使用 click(),但结果相同。

可能是什么问题?

最佳答案

这是一项安全功能。一些浏览器不允许非手动点击文件输入。您可以阅读更多相关信息 herehere .

为什么不能以编程方式触发文件输入选择?

Most browsers prevent submitting files when the input field didn'treceive a direct click (or keyboard) event as a security precaution.Some browsers (e.g. Google Chrome) simply prevent the click event,while e.g. Internet Explorer doesn't submit any files that have beenselected by a programmatically triggered file input field. Firefox 4(and later) is so far the only browser with full support for invoking"click"-Events on a completely hidden (display: none) file inputfield.

关于javascript - 触发点击输入文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25886480/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com