是否可以防止出现文件对话框?为什么?

jay*_*rjo 4 html filedialog file input event-handling

假设我输入了[type = file]元素,我想拦截onclick事件并阻止在不满足条件时出现文件对话框.可能吗?为什么,如果 - 不是吗?

Joe*_*Joe 12

Soufiane的代码要求您在页面上有一个名为jQuery的Javascript库.如果你没有它,你可以在http://www.jquery.com上获得它或者使用普通的Javascript中的东西:

HTML

<input type="file" id="openf" />
Run Code Online (Sandbox Code Playgroud)

JS:

document.getElementById('openf').onclick = function (e) { e.preventDefault(); };
Run Code Online (Sandbox Code Playgroud)