当前位置: 动力学知识库 > 问答 > 编程问答 >

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

问题描述:

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?

网友答案:

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();
});
分享给朋友:
您可能感兴趣的文章:
随机阅读: