我一直在使用jquery datepickers localiztion文件和<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="70dp"
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:orientation="horizontal">
<TextView
android:id="@+id/dgOne"
android:layout_width="90.75dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:background="@drawable/line_white"
android:ems="10"
android:gravity="center_horizontal"
android:paddingBottom="20dp"
android:text="1"
android:textColor="@color/keyboard_digit"
android:textSize="26.25sp"
android:textStyle="bold" />
<TextView
android:id="@+id/dgTwo"
android:layout_width="90.75dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="22.25dp"
android:background="@drawable/line_white"
android:ems="10"
android:gravity="center_horizontal"
android:paddingBottom="20dp"
android:text="2"
android:textColor="@color/keyboard_digit"
android:textSize="26.25sp"
android:textStyle="bold" />
<TextView
android:id="@+id/dgThree"
android:layout_width="90.75dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="22.25dp"
android:background="@drawable/line_white"
android:ems="10"
android:gravity="center_horizontal"
android:paddingBottom="20dp"
android:text="3"
android:textColor="@color/keyboard_digit"
android:textSize="26.25sp"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="22.25dp"
android:gravity="center_horizontal"
android:orientation="horizontal">
<TextView
android:id="@+id/dgFour"
android:layout_width="90.75dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:background="@drawable/line_white"
android:ems="10"
android:gravity="center_horizontal"
android:paddingBottom="20dp"
android:text="4"
android:textColor="@color/keyboard_digit"
android:textSize="26.25sp"
android:textStyle="bold" />
<TextView
android:id="@+id/dgFive"
android:layout_width="90.75dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="22.25dp"
android:background="@drawable/line_white"
android:ems="10"
android:gravity="center_horizontal"
android:paddingBottom="20dp"
android:text="5"
android:textColor="@color/keyboard_digit"
android:textSize="26.25sp"
android:textStyle="bold" />
<TextView
android:id="@+id/dgSix"
android:layout_width="90.75dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="22.25dp"
android:background="@drawable/line_white"
android:ems="10"
android:gravity="center_horizontal"
android:paddingBottom="20dp"
android:text="6"
android:textColor="@color/keyboard_digit"
android:textSize="26.25sp"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="22.25dp"
android:gravity="center_horizontal"
android:orientation="horizontal">
<TextView
android:id="@+id/dgSeven"
android:layout_width="90.75dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:background="@drawable/line_white"
android:ems="10"
android:gravity="center_horizontal"
android:paddingBottom="20dp"
android:text="7"
android:textColor="@color/keyboard_digit"
android:textSize="26.25sp"
android:textStyle="bold" />
<TextView
android:id="@+id/dgEight"
android:layout_width="90.75dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="22.25dp"
android:background="@drawable/line_white"
android:ems="10"
android:gravity="center_horizontal"
android:paddingBottom="20dp"
android:text="8"
android:textColor="@color/keyboard_digit"
android:textSize="26.25sp"
android:textStyle="bold" />
<TextView
android:id="@+id/dgNine"
android:layout_width="90.75dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="22.25dp"
android:background="@drawable/line_white"
android:ems="10"
android:gravity="center_horizontal"
android:paddingBottom="20dp"
android:text="9"
android:textColor="@color/keyboard_digit"
android:textSize="26.25sp"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="22.25dp"
android:gravity="center_horizontal"
android:orientation="horizontal">
<TextView
android:id="@+id/dgEmpty"
android:layout_width="90.75dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:ems="10"
android:gravity="center_horizontal"
android:paddingBottom="20dp"
android:textColor="@color/keyboard_digit"
android:textSize="26.25sp"
android:textStyle="bold" />
<TextView
android:id="@+id/dgZero"
android:layout_width="90.75dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="22.25dp"
android:ems="10"
android:gravity="center_horizontal"
android:paddingBottom="20dp"
android:text="0"
android:textColor="@color/keyboard_digit"
android:textSize="26.25sp"
android:textStyle="bold" />
<ImageView
android:id="@+id/imgDelete"
android:layout_width="90.75dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="22.25dp"
android:ems="10"
android:gravity="center_horizontal"
android:paddingBottom="20dp"
android:src="@drawable/delete_button" />
</LinearLayout>
</LinearLayout>
代码:
datepicker.es
但在我的代码中,我需要使用此格式(function ($) { $.fn.datepicker.language["es-ES"] = {
days: ["Domingo", "Lunes", "Martes", "Miércoles", "Jueves", "Viernes", "Sábado"],
daysShort: ["Dom", "Lun", "Mar", "Mié", "Jue", "Vie", "Sáb"],
daysMin: ["Do", "Lu", "Ma", "Mi", "Ju", "Vi", "Sa"],
months: ["Enero", "Febrero", "Marzo", "Abril", "Mayo", "Junio", "Julio", "Agosto", "Septiembre", "Octubre", "Noviembre", "Diciembre"],
monthsShort: ["Ene", "Feb", "Mar", "Abr", "May", "Jun", "Jul", "Ago", "Sep", "Oct", "Nov", "Dic"],
today: "Hoy",
clear: "Borrar",
dateFormat: "dd/mm/yyyy",
timeFormat: "hh:ii",
firstDay: 1
};}(jQuery));
所以这段代码
yyyy-mm-dd
导致问题
$(legId)。数据(&#34;日期选择器&#34)。selectDate(newDate);
我认为因为日期格式。我怎么解决这个问题?
我知道一种方法就是这样做
$(".multi_datepicker").each((index: number, elem: Element): void => {
const target: JQuery<HTMLElement> = $(elem);
const elemMinDate: Date = new Date(target.attr("data-mindate"));
const elemMaxDate: Date = new Date(target.attr("data-maxdate"));
const defaultDate: Date = new Date(target.attr("data-defaultDate"));
target.datepicker({
language: gon.locale,
minDate: elemMinDate,
maxDate: elemMaxDate,
autoClose: true,
altFieldDateFormat: "yyyy-mm-dd",
onShow(inst, animationCompleted): boolean {
if (animationCompleted) {
return true;
}
const id: number = inst.$el.attr("id").split("_")[2];
if (id < 0) {
return true;
}
const previous: JQuery<HTMLElement> = $(`#search_legs_${id - 1}_date`);
if (previous.length === 0) {
return true;
}
const date: Date = new Date(previous.val() as string);
// TODO: Does this even do something?
// if (inst.currentDate < date) {
// inst.selectedDates = [date];
// }
inst.update("minDate", date);
},
onSelect(dateText, inst): void {
// This updates all the next dates.
const noCount: number = $("#search_no_legs").val();
let p: string = $("#search_legs_0_date").val();
const newDate: Date = new Date(dateText);
newDate.setDate(newDate.getDate() + 7);
for (let i = 1; i < noCount; i += 1) {
const legId = `#search_legs_${i}_date`;
if ($(legId).val() < p) {
$(legId).val(p);
$(legId).data("datepicker").selectDate(newDate);
}
p = $(legId).val();
}
}
}).data("datepicker").selectDate(defaultDate);
});
但是如果我有另一个日期选择器与另一个本地化和另一个日期格式,它将无法正常工作