gpt4 book ai didi

javascript - bootstrap datepicker - 突出显示第一个选定的日期

转载 作者:行者123 更新时间:2023-12-03 07:27:33 28 4
gpt4 key购买 nike

我找到了一些 fiddle ,并进行了更新,主要是将日期选择器显示为组件,没有输入。

http://jsfiddle.net/Luhbzxdn/

JavaScript 代码:

// Date Pickers
var month = ("January February March April May June July August September October November December").split(" ");
var now = new Date();
var nowformatted = now.getDate() + " " + month[now.getMonth()] + " " + now.getFullYear();
var dpOptions = {
format: 'dd MM yyyy',
startDate: now,
setDate: now,
};

var i = 0;

var datePicker1 = $("#date1").
val(nowformatted).
datepicker(dpOptions).
on('changeDate', function (e) {
console.log("dp1", i++);
datePicker2.datepicker('setStartDate', e.date);
});

var datePicker2 = $("#date2").
val(nowformatted).
datepicker(dpOptions).
on('changeDate', function (e) {
datePicker1.datepicker('setEndDate', e.date);
});

我遇到了麻烦,当我选择第一个日期时,我看到蓝色高亮,所以我可以知道选择了哪一天,但如果我单击第二个日期选择器,第一个选择的日期不再突出显示。有没有办法保留这些突出显示的元素,以便用户始终可以看到他选择的内容?

最佳答案

将其添加到 HTML 代码中:

<input type="text" id="first-date" />
<input type="text" id="last-date" />

并在 javascript 中使用此代码:

function myDateFormatter (dateObject) {
var d = new Date(dateObject);
var day = d.getDate();
var month = d.getMonth() + 1;
var year = d.getFullYear();
if (day < 10) {
day = "0" + day;
}
if (month < 10) {
month = "0" + month;
}
var date = day + "/" + month + "/" + year;

return date;
};


// Date Pickers
var month = ("January February March April May June July August September October November December").split(" ");
var now = new Date();
var nowformatted = now.getDate() + " " + month[now.getMonth()] + " " + now.getFullYear();
var dpOptions = {
format: 'dd MM yyyy',
startDate: now,
setDate: now,
};

var i = 0;

var datePicker1 = $("#date1").
val(nowformatted).
datepicker(dpOptions).
on('changeDate', function (e) {

$('#first-date').val(myDateFormatter(e.date));
console.log("dp1", i++);
datePicker2.datepicker('setStartDate', e.date);
});

var datePicker2 = $("#date2").
val(nowformatted).
datepicker(dpOptions).
on('changeDate', function (e) {
$('#last-date').val(myDateFormatter(e.date));
// datePicker1.datepicker('setEndDate', e.date);
});

关于javascript - bootstrap datepicker - 突出显示第一个选定的日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35938749/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com