gpt4 book ai didi

jQuery UI Datepicker - 多个日期选择

转载 作者:行者123 更新时间:2023-12-03 21:28:16 26 4
gpt4 key购买 nike

有没有办法使用 jQuery UI Datepicker 小部件来选择多个日期?

感谢所有帮助!如果无法使用 jquery UI 日期选择器,那么是否有类似的东西可以使用?

最佳答案

我需要做同样的事情,因此使用 onSelectbeforeShowDay 事件编写了一些 JavaScript 来实现这一点。它维护自己的选定日期数组,因此不幸的是,它没有与显示当前日期等的文本框集成。我只是将它用作内联控件,然后我可以在数组中查询当前选定的日期。< br/>我用过this code作为基础。

<script type="text/javascript">
// Maintain array of dates
var dates = new Array();

function addDate(date) {
if (jQuery.inArray(date, dates) < 0)
dates.push(date);
}

function removeDate(index) {
dates.splice(index, 1);
}

// Adds a date if we don't have it yet, else remove it
function addOrRemoveDate(date) {
var index = jQuery.inArray(date, dates);
if (index >= 0)
removeDate(index);
else
addDate(date);
}

// Takes a 1-digit number and inserts a zero before it
function padNumber(number) {
var ret = new String(number);
if (ret.length == 1)
ret = "0" + ret;
return ret;
}

jQuery(function () {
jQuery("#datepicker").datepicker({
onSelect: function (dateText, inst) {
addOrRemoveDate(dateText);
},
beforeShowDay: function (date) {
var year = date.getFullYear();
// months and days are inserted into the array in the form, e.g "01/01/2009", but here the format is "1/1/2009"
var month = padNumber(date.getMonth() + 1);
var day = padNumber(date.getDate());
// This depends on the datepicker's date format
var dateString = month + "/" + day + "/" + year;

var gotDate = jQuery.inArray(dateString, dates);
if (gotDate >= 0) {
// Enable date so it can be deselected. Set style to be highlighted
return [true, "ui-state-highlight"];
}
// Dates not in the array are left enabled, but with no extra style
return [true, ""];
}
});
});
</script>

关于jQuery UI Datepicker - 多个日期选择,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1452066/

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