x
 
<!DOCTYPE html>
<html>
<body>
<form action="/demo/htmldom/action_page.php">
  时间:<input type="time" id="myTime" name="usr_time">
  <input type="submit">
</form>
<p>单击“试一试”按钮可为时间字段设置 required 属性。</p>
<p><b>提示:</b>请在点击“试一试”按钮前后点击“提交”按钮,并查看效果。</p>
<button onclick="myFunction()">试一试</button>
<p id="demo"></p>
<script>
function myFunction() {
  document.getElementById("myTime").required = true;
  document.getElementById("demo").innerHTML = "required 属性已设置。现在必须在提交表格之前填写时间字段。";
}
</script>
</body>
</html>