<html>
<body>
<form action="form-action.php">
Time: <input type="time" id="myTime" name="usr_time">
<input type="submit">
</form>
<p>点击 "点我" 按钮为 time 字段设置 required 属性。</p>
<p><strong>提示:</strong> 在点击 "点我" 按钮前后点击 "提交" 按钮查看效果</p>
<button onclick="myFunction()">点我</button>
<p id="demo"></p>
<script>
function myFunction() {
document.getElementById("myTime").required = true;
document.getElementById("demo").innerHTML = " required 属性已设置,time 字段在标题提交前为必填字段。";
}
</script>
</body>
</html>