![]() |
想旅行的梨子 · javascript - js ...· 1 月前 · |
![]() |
大力的镜子 · 日期和时间类型 | TiDB 文档中心· 2 周前 · |
![]() |
还单身的蘑菇 · mysql时间戳如何转换-PingCAP ...· 2 周前 · |
![]() |
愤怒的伤疤 · django设置模板时间格式· 3 天前 · |
![]() |
英俊的紫菜 · MySQL :: MySQL 8.4 ...· 昨天 · |
![]() |
胆小的毛衣 · mybatis中foreach用法 - ...· 9 月前 · |
![]() |
礼貌的香菇 · 鼠标自动双击,试了很多办法都不行? - 知乎· 1 年前 · |
![]() |
耍酷的芹菜 · json 逗号转义字符_51CTO博客· 1 年前 · |
![]() |
温柔的豆浆 · Django ...· 1 年前 · |
![]() |
飘逸的汽水 · php - Laravel global ...· 2 年前 · |
redis 时间戳 |
https://cloud.tencent.com/developer/information/%E5%A6%82%E4%BD%95%E8%AE%BE%E7%BD%AE%E6%97%B6%E9%97%B4%E9%80%89%E6%8B%A9%E5%99%A8% |
![]() |
暴躁的机器猫
4 月前 |
设置时间选择器中的最大和最小时间通常涉及前端开发中的日期时间处理。以下是相关的基础概念、优势、类型、应用场景以及解决方案。
时间选择器(Date/Time Picker)是一种用户界面组件,允许用户选择日期和时间。它可以用于表单输入、日历事件安排等场景。
<input type="datetime-local">
或第三方库(如jQuery UI Datepicker、Flatpickr等)。
以下是一个使用HTML5和JavaScript设置时间选择器最大和最小时间的示例:
<!DOCTYPE html>
<html lang="en">
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Time Picker Example</title>
</head>
<label for="datetime">Select Date and Time:</label>
<input type="datetime-local" id="datetime">
<script src="script.js"></script>
</body>
</html>
document.addEventListener("DOMContentLoaded", function() {
const datetimePicker = document.getElementById('datetime');
// 设置最小时间
const minDate = new Date();
minDate.setFullYear(minDate.getFullYear(), minDate.getMonth(), minDate.getDate(), 9, 0); // 2023-10-01T09:00
datetimePicker.setAttribute('min', minDate.toISOString().slice(0, 16));
// 设置最大时间
const maxDate = new Date();
maxDate.setFullYear(maxDate.getFullYear(), minDate.getMonth(), minDate.getDate(), 17, 0); // 2023-10-01T17:00
datetimePicker.setAttribute('max', maxDate.toISOString().slice(0, 16));
});
<input>
元素,类型为
datetime-local
,用于选择日期和时间。
DOMContentLoaded
事件确保DOM完全加载后再执行脚本。
datetime-local
元素。
min
和
max
属性。
通过这种方式,你可以灵活地设置时间选择器的最大和最小时间,以满足特定的业务需求。
![]() |
大力的镜子 · 日期和时间类型 | TiDB 文档中心 2 周前 |
![]() |
愤怒的伤疤 · django设置模板时间格式 3 天前 |
![]() |
胆小的毛衣 · mybatis中foreach用法 - CSDN文库 9 月前 |
![]() |
礼貌的香菇 · 鼠标自动双击,试了很多办法都不行? - 知乎 1 年前 |
![]() |
耍酷的芹菜 · json 逗号转义字符_51CTO博客 1 年前 |