[英]Datepicker Jquery Set Second Date After Choosing First Date
I am building an accommodation rental search form. 我正在构建住宿租赁搜索表。 The website is ASPX based and I am using the JS Jquery Datepicker setup with CSS to make it work.
该网站是基于ASPX的,我正在使用带有CSS的JS Jquery Datepicker设置来使其工作。
I am able to make the date popup work and position correctly. 我能够使日期弹出窗口正常工作和定位。 However, when the website user chooses the first date, I need the second date popup window to open +2 days.
但是,当网站用户选择第一个日期时,我需要第二个日期弹出窗口才能打开+2天。 Or the second date to be set to +2 days.
或将第二个日期设置为+2天。
Does anyone know how to add JS code to my current setup to make this work? 有谁知道如何将JS代码添加到当前设置中以使其工作? Any help would be greatly appreciated as I looked at several posts about this topic and could not get it to work.
当我查看了有关该主题的几篇文章并且无法使它起作用时,任何帮助将不胜感激。
Below is the JS that I am using so far:- 以下是我到目前为止使用的JS:-
<script>
$(document).ready(function() {
$("#txtDate").datepicker({
showOn: 'button',
buttonText: 'Show Date',
numberOfMonths:1,
buttonImageOnly: true,
buttonImage: '/images/cont/mobile/calendar.png'
});
$("#txtDate2").datepicker({
showOn: 'button',
buttonText: 'Show Date',
numberOfMonths:1,
buttonImageOnly: true,
buttonImage: '/images/cont/mobile/calendar.png'
});
$(".ui-datepicker-trigger").mouseover(function() {
$(this).css('cursor', 'pointer');
});
});
</script>
And this is the HTML:- 这是HTML:-
<input type='text' id='txtDate' name="checkin" value=" " />
<input type="text" id="txtDate2" name="checkout" value=" " />
You can get the selected date and add 2 days to it based on onSelect
event of the first datepicker. 您可以获取所选日期,并根据第一个日期选择器的
onSelect
事件向其添加2天。
$(function () { $("#txtDate").datepicker({ //showOn: 'button', buttonText: 'Show Date', numberOfMonths: 1, buttonImageOnly: true, buttonImage: '/images/cont/mobile/calendar.png', onSelect: function(dateText, inst) { var txtDate = $(this).datepicker('getDate'); txtDate.setDate(txtDate.getDate() + 2); $("#txtDate2").datepicker('setDate', txtDate); } }); $("#txtDate2").datepicker({ //showOn: 'button', buttonText: 'Show Date', numberOfMonths: 1, buttonImageOnly: true, buttonImage: '/images/cont/mobile/calendar.png' }); $(".ui-datepicker-trigger").mouseover(function () { $(this).css('cursor', 'pointer'); }); });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.css" /> <script src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script> <input type='text' id='txtDate' name="checkin" value=" " /> <input type="text" id="txtDate2" name="checkout" value=" " />
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.