Html 必需属性设置为非必需

Jea*_*ude 3 html webforms

我有一些代码如下:

<label class="control-label col-sm-4" for="datepicker">Date of Birth</label>
<div class="col-sm-8" ><input class="form-control col-sm-10" type="text" id="datepicker" name="datepicker" required="true" value="<?php if(isset($_SESSION['DOB'])) echo $_SESSION['DOB'] ?>"></div>
Run Code Online (Sandbox Code Playgroud)

我的问题是我不希望这个“出生日期”字段再成为必填字段。如何将该字段设置为非必填?

我尝试过设置,required="false"但这不起作用。

非常感谢任何建议,非常感谢让-克洛德

Luk*_*ili 8

必需的属性不采用属性值。它只是 required="true",或 required="required",或者只是设置

<input type="text" required />
Run Code Online (Sandbox Code Playgroud)

也会使它成为必需的。只需取消设置所需的属性即可。如果您尝试在某些用户操作(使用 JavaScript)后取消设置它,请使用 .removeAttribute("required")函数。