我想限制用户从.xml扩展名以外的选择对话框中选择文件。
我有下面的代码,
<input type='file' accept='.xml' onChange={handleselectedfile}/>
现在,该用户仍然可以从.xml更改为All files并选择文件。
我如何确定或限制用户选择除.xml扩展名类型之外的文件。
有人可以帮我吗 谢谢。
您可以尝试在onChange上添加验证
像这样的JavaScript
var fileName = document.getElementById('file').value.toLowerCase();
if(!fileName.endsWith('.xml'){
alert('You can upload xml files only.');
return false;
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句