html - 使隐藏字段成为必需
问题描述
这是我的代码:
<label for="uploadFile" class="custom-uploadFile">
<i class="fa fa-cloud-upload"></i> UPLOAD ID
</label>
<input class="form-control input-lg" name="picture" id="uploadFile" type="file" style="display:none;" required>
我想让这个上传字段是必需的,但输入是隐藏的。我必须使用一些javascript或什么来解决这个问题,因为我看了很多tuto但没有工作!谢谢
解决方案
如果您想查看表单验证消息,您可以使用 opacity 隐藏输入。
#uploadFile {
opacity: 0;
width: 0;
float: left; /* Reposition so the validation message shows over the label */
}
div {
text-align: center;
}
<form>
<input name="picture" id="uploadFile" type="file" required>
<label for="uploadFile">Upload label</label>
<div><input name="submit" type="submit"></div>
</form>
推荐阅读
- react-state-management - 是否可以使用 useSWR 知道重新验证的原因?
- matlab - 线性回归外推大数据分析
- excel - 获取和比较字符串中的整数
- javascript - jQuery .load() 函数后,jQuery sortable() 不起作用
- node.js - 修改 server.js 以使用 heroku 部署处理 api 调用
- google-drive-api - Google Drive API - 转移整个驱动器的所有权(如网络界面)
- angular - ng-template 内容不会在 Angular 中使用引导工具提示的 title 属性内呈现
- vba - 运行时错误“3265”:在此集合中找不到项目。Access 中的 VBA 模块
- sql - 使用 @Formula(休眠注释)时无法提取 ResultSet
- python - 如何在异构列表和字典中使用递归