jQuery UI Datepicker添加天数 [英] jQuery UI Datepicker Add Days

查看:95
本文介绍了jQuery UI Datepicker添加天数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图为酒店网站上的客房预订创建范围系统,并且使用jQuery UI Datepicker允许用户选择入住日期.然后,我想要做的是创建另一个简单的"Number of Nights"字段,并让jQuery Datepicker获取签入日期,添加夜晚数,然后将结果日期设置为隐藏输入的值(正确的日期)格式).看起来像这样:

I'm attempting to create something of range system for booking rooms on a hotel website and I'm using jQuery UI Datepicker to allow the user to select their check in date. What I then want to do is create another field that's simple "Number of Nights" and have jQuery Datepicker take the check in date, add the number of nights, and set the resulting date as the value of a hidden input (in the correct date format). It would look something like this:

<input type="text" name="arrivalDate" class="datepicker">
<input type="text" name="numOfNights">
<input type="hidden" name="departureDate" value="arrivalDate + number of nights">

这可能吗?预先感谢.

(注意:我将以这种形式从数据库中获取"数据,这有点气质,除了几个可查询的值之外,我无权访问它.)

(Note: The database I'll be "get"-ing from with this form is a little temperamental and I don't have access to it beyond just a few query-able values.)

推荐答案

以上内容可以通过以下代码实现-

The above can be achieved by following code -

 $('input[name="arrivalDate"]').datepicker({

     //your other configurations.     

     onSelect: function(){
     var start = $('input[name="arrivalDate"]').val();
     var nights = $('input[name="numOfNights"]').val();
     var date = new Date(start);
     var d = date.getDate();
     var m = date.getMonth();
     var y = date.getFullYear();
     var edate= new Date(y, m, d+nights);
     $('input[name="departureDate"]').val(edate);
    }
 });

这篇关于jQuery UI Datepicker添加天数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆