简体   繁体   English

输入类型=“文件”自动点击

[英]input type=“file” auto click

当页面首次打开时,如何自动打开输入类型=“文件”的浏览对话框?

I don't think you should do this. 我认为你不应该这样做。 If you've ever visited a MySpace page, you know how frustrating it can be when a web page activates things on its own when the page loads. 如果您曾访问过MySpace页面,那么当页面加载时,当网页自行激活时,您会感到非常沮丧。

Don't violate how the UI is supposed to work, let the user ask for the dialog. 不要违反用户界面的工作方式,让用户请求对话框。

Besides, if the users instinctively closes it like a popup, and then realizes they needed it, it may not be obvious how they should get the dialog back. 此外,如果用户本能地像弹出窗口一样关闭它,然后意识到他们需要它,那么他们应该如何恢复对话可能并不明显。 Then they will reload the page just to show the dialog again -- all frustrating things you could be avoiding. 然后他们会重新加载页面只是为了再次显示对话框 - 所有令人沮丧的事情都可以避免。

That being said, I'm not sure why you want to do this in the first place. 话虽如此,我不确定你为什么要这样做。 This is just my first reaction to what you're asking. 这只是我对你问的第一反应。

This is completely impossible in Firefox. 这在Firefox中完全不可能。

In other browsers, you can: 在其他浏览器中,您可以:

document.getElementById('inputId').click();

fire the click event on the button on document ready 在文档准备好的按钮上触发click事件

$(document).ready(function() {
    $("#buttonid").click();
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM