我想在加载页面时显示文件对话框。 我试着用JS触发jQuery文档就绪事件中文件输入的点击事件。但是,这种方法只适用于IE11,它不适用于Chrome(41.0.2272.118)。 如何让它在Chrome中工作?如何在Chrome中加载页面时使用JavaScript显示文件对话框
这里是我的代码不会在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>
你不能,大多数浏览器不会允许你。文件上传对话框只能由用户在文件上传输入中实际点击(或关注 - >输入)而显示。 –