Is it possible to prevent file dialog from appearing? Why?

巧了我就是萌 提交于 2019-12-07 10:10:29

问题


Suppose I have input[type=file] element and I want to intercept onclick event and prevent file dialog from appearing if conditions are not met. Is it possible? And why, if - not?


回答1:


Soufiane's code requires that you have a Javascript library called jQuery on your page. If you don't have it, you can get it at http://www.jquery.com or use something in plain Javascript:

HTML

<input type="file" id="openf" />

JS:

document.getElementById('openf').onclick = function (e) { e.preventDefault(); };



回答2:


HTML:

<input type="file" class="openf" />

JS:

$('.openf').click(function(e){
      e.preventDefault();
});


来源:https://stackoverflow.com/questions/7350134/is-it-possible-to-prevent-file-dialog-from-appearing-why

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!