开发者

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

开发者 https://www.devze.com 2023-04-04 01:28 出处:网络
Suppose I have input[type=file] element and I want to interc开发者_如何学Cept onclick event and prevent file dialog from appearing if conditions are not met. Is it possible? And why, if - not?Soufiane

Suppose I have input[type=file] element and I want to interc开发者_如何学Cept onclick event and prevent file dialog from appearing if conditions are not met. Is it possible? And why, if - not?


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(); };


HTML:

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

JS:

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

精彩评论

暂无评论...
验证码 换一张
取 消