我想页面加载后显示文件对话框。 我尝试使用JS来触发jQuery文档就绪事件中文件输入的点击事件。但是这种方法仅适用于IE11,它不适用于Chrome(41.0.2272.118)。 我怎样才能让它在 Chrome 中工作?
这是我的代码,它在 Chrome 中不起作用,但在 IE 中起作用:
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>My HTML File</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
</head>
<body >
<input type="file" id="a" />
<script>
$(document).ready(function () {
Go();
});
function Go() {
var input = $('input');
input.click();
console.log('Gooooooooooooooo');
}
</script>
</body>
</html>
最佳答案
IE 将允许您在 type='file' 上触发 .click 事件,但出于安全原因,大多数其他浏览器不会。然而,there is a solution这可能对你有用。
关于javascript - 在 Chrome 中加载页面后如何使用 JavaScript 显示文件对话框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29473641/