php - 根据引导日期选择器中的下拉选择预选择日期?
问题描述
任何人都知道,我可以如何实现以下目标:
- 如果有人选择“仅限周末”选项,则所有周末日期都将选择从当前月份到下个月的指定日期。
- 如果有人选择“仅适用于工作日”选项,则将选择从当前月份到下个月的指定日期的所有工作日日期。
- 如果有人选择“仅限周五”选项,则将选择从当前月份到下个月的指定日期的所有周五日期。
有人知道我可以从哪里开始吗?
$('#dt_1').datepicker({
rtl: KTUtil.isRTL(),
todayHighlight: true,
templates: arrows,
startDate: date, //disable all old dates
setDate: date, //tomorrow's date allowed
multidate: true,
format: 'dd/mm/yyyy'
});
解决方案
在另一篇stackoverflow帖子的帮助下,我找到了实现这一目标的解决方案: 使用php获得周末
PHP代码:
//weekend.....
$now = strtotime("now");
$end_date = strtotime("+3 weeks");
$weekend_array = array();
while (date("d-m-Y", $now) != date("d-m-Y", $end_date)) {
$day_index = date("w", $now);
if ($day_index == 0 || $day_index == 6) {
// Print or store the weekends here.
//echo "<br>".$day_index."- Date: ".date("d-m-Y", $now);
$weekend_array[] = date("d-m-Y", $now);
}
$now = strtotime(date("d-m-Y", $now) . "+1 day");
}
//friday only....
$now = strtotime("now");
$end_date = strtotime("+3 weeks");
$friday_array = array();
while (date("d-m-Y", $now) != date("d-m-Y", $end_date)) {
$day_index = date("w", $now);
if ($day_index == 5) {
// Print or store the weekends here.
//echo "<br>".$day_index."- Date: ".date("d-m-Y", $now);
$friday_array[] = date("d-m-Y", $now);
}
$now = strtotime(date("d-m-Y", $now) . "+1 day");
}
//weekdays......
$now = strtotime("now");
$end_date = strtotime("+3 weeks");
$weekday_array = array();
while (date("d-m-Y", $now) != date("d-m-Y", $end_date)) {
$day_index = date("w", $now);
if ($day_index >= 1 && $day_index <= 5) {
// Print or store the weekends here.
//echo "<br>".$day_index."- Date: ".date("d-m-Y", $now);
$weekday_array[] = date("d-m-Y", $now);
}
$now = strtotime(date("d-m-Y", $now) . "+1 day");
}
Javascript代码:
$(document).ready( function () {
$("#sel_dropdown").change(function() {
$( "select option:selected" ).each(function() {
var v = $(this).val();
if(v == 1) {
//weekend only....
$('#dt_1').datepicker('setDates',[<?php
$i=0;
for($i=0;$i<=count($weekend_array);$i++) {
echo "'".$weekend_array[$i]."',";
}
?>]);
}
if(v == 2) {
//Friday only.....
$('#dt_1').datepicker('setDates',[<?php
$i=0;
for($i=0;$i<=count($friday_array);$i++) {
echo "'".$friday_array[$i]."',";
}
?>]);
}
if(v == 3) {
//Weekdays only....
$('#dt_1').datepicker('setDates',[<?php
$i=0;
for($i=0;$i<=count($weekday_array);$i++) {
echo "'".$weekday_array[$i]."',";
}
?>]);
}
if(v == 4) {
//custom option....
$('#dt_1').data('datepicker').setDate(null);
}
});
});
});
</script>
希望这对寻找此类解决方案的任何人都有用。
推荐阅读
- sql - 存储在字符串中的 OPENQUERY 查询因 EXEC 而失败
- r - 根据 R 中另一列的 < 或 >= 数值创建非数值列
- php - 我可以在父构造函数中将对象动态转换为特定的子类吗?
- twig - ModuleNode 是否始终是 Twig 节点层次结构中的顶级节点?
- python - autopytoexe 和 Google 表格 UnknownApiNameOrVersion:名称:表格版本:v4
- c# - 高效查询多张表c#linq
- flutter - 如果存在 Dart 从字符串中删除第一个逗号
- acumatica - 从一个自定义字段到另一个自定义字段的 Acumatica 数据
- org-mode - 如何通过(ox-)hugo并排导出文本以在组织模式之外进行比较
- linux - 如何更改第二个 SSD 上新分区的路径?