首页 > 解决方案 > 使隐藏字段成为必需

问题描述

这是我的代码:

 <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但没有工作!谢谢

标签: html

解决方案


如果您想查看表单验证消息,您可以使用 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>


推荐阅读