- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我使用此处找到的基本模板构建了一个日期选择器:
https://github.com/qodesmith/datepicker/blob/master/README.md
我的代码是:
const picker = datepicker(document.querySelector('#datepicker'), {
// Event callbacks.
onSelect: function(instance) {
var instanceSplit = instance.dateSelected.toString().split(" " ,4)
var instanceClean = instanceSplit.toString().replace(/,/g, ' ')
selectedDate = instanceClean
console.log(selectedDate)
update()
},
onShow: function(instance) {
console.log('Calendar showing.');
},
onHide: function(instance) {
console.log('Calendar hidden.');
},
onMonthChange: function(instance) {
// Show the month of the selected date.
},
// Customizations.
formatter: function(el, date, instance) {
// This will display the date as `1/1/2019`.
el.value = date.toDateString();
},
position: 'tr', // Top right.
startDay: 1, // Calendar week starts on a Monday.
customDays: ['S', 'M', 'T', 'W', 'Th', 'F', 'S'],
customMonths: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
overlayButton: 'Go!',
overlayPlaceholder: 'Enter a 4-digit year',
// Settings.
alwaysShow: true, // Never hide the calendar.
dateSelected: new Date(), // Today is selected.
maxDate: new Date(2019, 5, 21), // Jan 1st, 2099.
minDate: new Date(2016, 5, 1), // June 1st, 2016.
startDate: new Date(), // This month.
});
虽然一切正常,但我想将 maxDate 设置为从今天算起的一周。虽然我知道我可以做这样的事情:
var firstDay = new Date();
var nextWeek = new Date(firstDay.getTime() + 7 * 24 * 60 * 60 * 1000);
我不知道如何将变量传递到 maxDate:
对象中。如果我在格式化程序函数中或全局声明 maxDate 变量,我无法将其传递到对象中。
事实上,我无法真正弄清楚下面的整个代码是如何工作的。我不确定格式化程序函数在做什么,也不清楚最后的对象如何与整个函数相关。对于这个有点普遍的问题表示歉意,但我发现日期选择器文档令人困惑。
最佳答案
您可以尝试内联 +7 天计算。
maxDate: new Date(new Date().getTime() + 7 * 24 * 60 * 60 * 1000),
关于javascript - 使用变量修改日期选择器中的 maxDate 和 minDate,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56535624/
我有这两个日期选择器: Start date:
我使用日期和时间选择器,但以下功能无法正常工作。 我猜时间选择器 minDate 函数 jQuery UI 与时间选择器有冲突 我正在更改位置脚本并删除时间选择器中的 minDate 函数,但无法正常
我将 Nest 与类验证器一起使用,并尝试使用 @isDateString() 验证 UI 提供的日期是否不早于今天。和 @MinDate() export class SchemaDto {
我有 2 个日期选择器,如下所示: $(function() { $( "#datepicker1, #datepicker2" ).datepicker({ minDate: 'to
我有两个日期选择器(jqueryui),我想将第二个输入(minDate 属性)限制为第一个输入中选择的值。我该怎么做?我编写了以下代码,但没有成功: $("#picker1").button()
我有以下两个日期选择器对象,但我无法得到我想要的,因为我陷入了 minDate 和 maxDate 选项: 这将日期限制为 future 的日期。 我想要的:将当前日期的日期限制为 30 年时间。 我
我正在使用trentrichardson.com 的日期时间选择器。 我有一个带有两个输入字段的表单:从和到,我希望能够动态地将 minDate 设置为我的“to”字段等于该值我的“发件人”字段。 我
我在同一页面中有两个日期选择器,我想根据第一个日期选择器更改第二个日期选择器的 minDate 。这是我的代码: $("#datepickerDepart" ).datepicker({
在这里,我选择的最大日期为当前日期后 3 周。但实际上我不想在本周结束之前改变最大日期。我想要这样的东西,当本周再次结束时,最大日期更改为下周末。 jQuery(document).ready(fun
我在我的网站上使用 Jquery datepicker,以便客户选择所需的交货日期。目前我已将 minDate 设置为 4(周末或节假日除外)。我刚刚意识到我需要考虑一天中的时间,这样如果有人在下午
我希望以下的日期范围从 65 年前开始到 18 年前结束。相反,minDate 数字将被忽略,并设置为结束日期之前 10 年。无论我在 minDate 中输入什么值,都没有区别。 $(function
我正在为我的 CodeIgniter 应用程序使用 AdminLte 模板,并从中使用 Datepicker 插件。我正在尝试添加 minDate 功能以限制用户访问当前日期之前的日期,但是 minD
我有两个 jqgrid。在从第一个网格中选择任何行时,我的第二个网格正在加载。我想编辑第二个网格(使用内联编辑)。第二个网格中有一个“voucherDate”列,第一个网格中有一个“loanReaso
我试图用日期选择器做的是,当它第一次显示时,显示当前日期加上 6 个月,你可以用 startDate 来做,但是回月按钮被禁用。我试图为今天的日期设置一个 minDate,同样的交易,一个月后退按钮被
我有两个日期选择器“startDate”和“targetDate”。我想将“targetDate”的minDate设置为“startDate”的值。以下代码不起作用。即,未设置“targetDate”
我需要一些有关 jQuery 日期选择器问题的指导,当然我正在监督一些细节。 我正在尝试为两个日期选择器设置一些最小日期;我通过 ajax 获取一条包含描述、开始日期和结束日期的消息,并在表单上显示这
我正在处理以前编写的 datetimepicker 对象。它看起来如下: $('#startDate').datetimepicker({ monthNames: DATE_TIME_MONT
我已经为我的 DatePicker View 设置了一个 minDate() 。现在的问题是我仍然可以从指定的最短日期之前的日期中进行选择。 我的java: long thirtyDaysInMill
我需要将 minDate 属性应用到 Rails 应用程序中的日期选择器作为今天的日期。 在_admin_controls.html.erb中 "datetime form-cont
我正在使用 Bootstrap 日期时间选择器,这是我的脚本 $('.start_datetime, .end_datetime').datetimepicker({ format: 'YYY
我是一名优秀的程序员,十分优秀!