Javascript 防止html输入类型文件显示“打开”对话框
长话短说,我需要能够阻止来自Javascript 防止html输入类型文件显示“打开”对话框,javascript,html,input-type-file,Javascript,Html,Input Type File,长话短说,我需要能够阻止来自input type=“file”的默认操作。换句话说,当用户单击“浏览”或“选择文件”时,我不想显示系统的“打开”对话框。我已经让“替换”对话框工作,但系统的“打开”对话框仍然出现 下面是我目前正在努力实现的一个示例。(注:我正在使用Chrome 21) 有什么想法吗?怎么样 <input type="file" onclick="return false" /> 明白了。我需要禁用标记,然后使用setTimeout方法重新启用它 <html
input type=“file”
的默认操作。换句话说,当用户单击“浏览”或“选择文件”时,我不想显示系统的“打开”对话框。我已经让“替换”对话框工作,但系统的“打开”对话框仍然出现
下面是我目前正在努力实现的一个示例。(注:我正在使用Chrome 21)
有什么想法吗?怎么样
<input type="file" onclick="return false" />
明白了。我需要禁用标记,然后使用
setTimeout
方法重新启用它
<html>
<head>
<script type="text/javascript">
<!--
file_onclick = function(o)
{
// Show custom dialog instead...
o.disabled = true;
setTimeout(function() { o.disabled = false; }, 1);
};
//-->
</script>
</head>
<body>
<input type="file" onclick="javascript: file_onclick(this);" />
</body>
</html>
谢谢,但这是我尝试的第一件事,但它不起作用。请在此处检查正确答案:
<html>
<head>
<script type="text/javascript">
<!--
file_onclick = function()
{
// Show custom dialog instead...
return false;
};
//-->
</script>
</head>
<body>
<input type="file" onclick="return file_onclick();" />
</body>
</html>
<html>
<head>
<script type="text/javascript">
<!--
file_onclick = function(o)
{
// Show custom dialog instead...
o.disabled = true;
setTimeout(function() { o.disabled = false; }, 1);
};
//-->
</script>
</head>
<body>
<input type="file" onclick="javascript: file_onclick(this);" />
</body>
</html>