如果HTML文件输入字段为空,是否可以禁用表单提交? [英] Can a form submit be disabled if a HTML file input field is empty?

查看:186
本文介绍了如果HTML文件输入字段为空,是否可以禁用表单提交?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在一个仅包含一个

 < input id =fileInputname =BugReporttype =文件/> 

输入字段,如果文件输入是空的,我想禁用Submit按钮还没有选择)。有没有推荐的方法来做到这一点?

解决方案

所需的属性添加到输入中。它只能在支持它的浏览器中工作,所以你应该有一个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文件输入字段为空,是否可以禁用表单提交?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆