我有两个本地日期时间(开始时间和结束时间(的输入。我想将开始日期限制为只选择最后72小时,但我不能限制未来的时间。我只想要今天,只想要三天。结束时间仅限今天和接下来的3天。这是我的代码:
<input type="datetime-local" name="start_timestamp" id="start_timestamp" required>
<input type="datetime-local" name="end_timestamp" id="end_timestamp" required>
<script>
//Do not let to select START TIME in the PAST
var today = new Date();
var past = new Date(today.setDate(today.getDate() - 3)).toISOString().slice(0, 16);
document.getElementsByName("start_timestamp")[0].min = past;
document.getElementsByName("start_timestamp")[0].max = today;
</script>
请参阅此处的可能修复程序。
<input type="datetime-local" name="start_timestamp" id="start_timestamp" required>
<input type="datetime-local" name="end_timestamp" id="end_timestamp" required>
<script>
//Do not let to select START TIME in the PAST
let today = new Date();
let past = new Date(today.setDate(today.getDate() - 3)).toISOString().slice(0, 16);
today = new Date().toISOString().slice(0, 16);
document.getElementsByName("start_timestamp")[0].min = past;
document.getElementsByName("start_timestamp")[0].max = today;
document.getElementsByName("end_timestamp")[0].min = past;
document.getElementsByName("end_timestamp")[0].max = today;
</script>