本文介绍了如果HTML文件输入字段为空,是否可以禁用表单提交?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在一个仅包含一个将所需的属性添加到输入中。它只能在支持它的浏览器中工作,所以你应该有一个JavaScript的替代方案(< form onSubmit =if(document.getElementById('fileinput')。value =='')return false ;> 或者沿着这些行的东西)
In a form which contains only a
<input id="fileInput" name="BugReport" type="file" />input field, I would like to disable the Submit button if the file input is empty (no file was chosen yet). Is there a recommended way to do this?
解决方案Add the required attribute to the input. It'll only work in browsers that support it, so you should have a JavaScript alternative (<form onSubmit="if(document.getElementById('fileinput').value == '') return false;"> or something along those lines).
这篇关于如果HTML文件输入字段为空,是否可以禁用表单提交?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!