两个DateField控件,分别为开始时间和结束时间。当选择完结束时间后,自动计算这两个时间段所间隔的月或天数。
<ext:DateField runat="server" ID="extdate_start_date" LabelStyle=" text-align:right; " FieldLabel="开始时间" Vtype="daterange"> <CustomConfig> <ext:ConfigItem Name="endDateField" Value="#{extdate_end_date}" Mode="Value" /> </CustomConfig> <Listeners> <Change Fn="GetBusiDay" /> </Listeners> </ext:DateField>
<ext:DateField runat="server" ID="extdate_end_date" LabelStyle=" text-align:right; " FieldLabel="结束时间" Vtype="daterange"> <CustomConfig> <ext:ConfigItem Name="startDateField" Value="#{extdate_start_date}" Mode="Value" /> </CustomConfig> <Listeners> <Change Fn="GetBusiDay" /> </Listeners> </ext:DateField>
Js代码:
function GetBusiDay() { if (extdate_start_date.getValue() == "" || extdate_end_date.getValue() == "") return; var sday = Ext.util.Format.date(extdate_start_date.getValue(), 'Y/m/d'); var eday = Ext.util.Format.date(extdate_end_date.getValue(), 'Y/m/d'); var end = new Date(eday); var start = new Date(sday); var time = end.getTime() - start.getTime(); var days = parseInt(time / (1000 * 60 * 60 * 24))+1; extnumb_busi_day.setValue(days); }
注意一定要转换日期格式 //日期格式为yyyy-mm-dd转换成yyyy/mm/dd