防止 html 输入类型文件显示打开的对话框

vbg*_*yny 3 html javascript input-type-file

长话短说,我需要能够阻止input type="file". 换句话说,当用户单击“浏览”或“选择文件”时,我不想显示系统打开的对话框。我已经可以使用替换对话框,但系统的打开对话框仍然出现。

以下是我目前正在尝试实现此目标的示例。(PS:我使用的是Chrome 21)

<html>
<head>

<script type="text/javascript">
<!--

 file_onclick = function()
 {
  // Show custom dialog instead...
  event.stopPropagation(); // Doesn't work
  return false; // Neither does this
 };

//-->
</script>

</head>
<body>
  <input type="file" onclick="javascript: file_onclick();" />
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

有任何想法吗?

Mus*_*usa 5

怎么样

<input type="file" onclick="return false" />
Run Code Online (Sandbox Code Playgroud)

或者如果您需要该file_onclick功能

<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>
Run Code Online (Sandbox Code Playgroud)