简体   繁体   English

我只需要在开始日期选择的日期选择器中显示未来一个月的日期

[英]I need to show only future one month dates in the date picker from the start date selection

enter code here

 $("#StartDate").datepicker({ dateFormat: 'dd/mm/yy', onSelect: function (selectedDate) { if (this.id == 'StartDate') { //console.log(selectedDate);//2014-12-30 var arr = selectedDate.split("/"); var date = new Date(arr[2]+"-"+arr[1]+"-"+arr[0]); var d = date.getDate(); var m = date.getMonth(); var y = date.getFullYear(); var minDate = new Date(y, m, d + 1); $("#EndDate").datepicker('setDate', minDate); } } }); $("#EndDate").datepicker({dateFormat: 'dd/mm/yy'});
 <input id="StartDate" type="text" name="StartDate"> <input id="EndDate" class="datepicker" type="text" name="EndDate">

Any required plugins given are appreciable.给出的任何必需的插件都是可观的。

Here the requirement is like I have two input fields one is for start date and another is for end date for eg if the select start date as 21-05-2020 and auto automatically the end date input filed should fetch the future one month dates as 21-06-2020.这里的要求就像我有两个输入字段,一个用于开始日期,另一个用于结束日期,例如,如果 select 开始日期为 21-05-2020 并且自动结束日期输入字段应获取未来一个月的日期为2020 年 6 月 21 日。 finally the output should be like start date: 21-05-2020 to end date: 21-06-2020.最后 output 应该像开始日期:21-05-2020 到结束日期:21-06-2020。

You just need to add both minDate and maxDate properties, something like this (click the Run code snippet button down below for a live demo):您只需要添加minDatemaxDate属性,如下所示(单击下方的运行代码片段按钮以进行现场演示):

 $(function() { $("#datepicker").datepicker({ minDate: 0, // ban dates in the past maxDate: "+1M" // allow only 1 month in the future }); });
 <link href="https://code.jquery.com/ui/1.12.1/themes/smoothness/jquery-ui.css" rel="stylesheet" type="text/css" /> <script src="https://code.jquery.com/jquery-3.1.0.js"></script> <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script> <body> <p>My cool date Date: <input type="text" id="datepicker"></p> </body>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在日期选择器中进行验证,仅显示当前日期起的最近5个月的日期 - validation in date picker, only show last 5 month date from current date 如何在引导程序日期选择器中显示过去的日期以供选择? - How to show past dates for selection in bootstrap date picker? 在Dojo Date Picker中禁用将来的日期? - Disable future dates in Dojo Date Picker? 日期选择器-禁用将来的日期范围 - Date Picker - disabling a range of dates in the future 我想制作只有年份和月份选择器的日期范围选择器 - I want to make date range picker with only Year and month picker jQuery日期选择器-从第一个日期选择器中选择之后禁用日期 - jQuery date picker - Disable dates after the selection from the first date picker 如何显示开始日期在一个月内而结束日期在另一个月内的元素? - How do I show elements that have start date in one month and end date in another? 根据选择禁用jQuery Date Picker中的日期 - Disabling dates in jQuery Date Picker based on selection 相对于在另一个文本框中选择月份,如何仅在日期选择器中显示所选月份的日期? - How to display selected month dates only in date picker with respect to selecting month in another text box? Airbnb 反应日期范围选择器仅显示当前月份日历未选择日期月份日历 - Airbnb react date range picker only showing current month calendar not selected dates month calender
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM