日期戳动态最小/最大日期 [英] Datepicker dynamic min / max dates

查看:139
本文介绍了日期戳动态最小/最大日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在建立的网站上使用jQuery datepicker插件。我需要用户从指定的日期范围内选择两个日期。这是很简单的。



问题是,允许的日期范围会根据另一个选择框(建筑名称)而改变。所以我需要发现的是在mysql数据库中查找建筑物,返回允许的最小和最大日期,并使用datepicker来允许用户选择允许范围内的日期范围。



在我的主页上,我目前正在使用:

  $('#dateStartMainChart')load url); 

加载输出的php文件:

 < script> 
$(function(){
$(#dateEndMainChartSelect).datepicker({
dateFormat:'yy-mm-dd',
defaultDate:-1,
minDate:new Date(2011,03,03),
maxDate:+0,
firstDay:1,
changeMonth:true,
changeYear:true
});
});
< / script>
< input type =textclass =textvalue = 2011-03-04 id =dateEndMainChartSelectalign =center/>

minDate和maxDate已从mysql数据库中正确填充。但是,结果是我只是在主页面上找到一个包含日期的文本框,而不是datepicker元素。



任何想法?

解决方案

好的,我终于弄清楚了。我最初定义和使用datepicker是正常的。当我需要动态更新时,我使用:

  $。getScript('url.php',function(){updateDate ();}); 

在我的情况下,我使用这个更改选择框。



调用查询mysql数据库的php文件输出以下内容(使用echo):

  function updateDate(){
$(#dateStartMainChartSelect).datepicker('change',{
minDate:new Date(2011,01,01),
maxDate:new Date ,02,01)
});
}

您可以在此处添加任何要更改的datepicker选项。感谢JasCav,我最终在正确的地方找到解决方案。


I'm using the jQuery datepicker plugin on a site I am building. I need users to be able to pick two dates from within a specified range of dates. This is straightforward enough to do.

The problem is that the allowable range of dates changes depending on another select box (with building names in). So what I need to happen is to look up the building in a mysql database, return the min and max date allowed and use the datepicker to allow users to choose a date range within the allowable range.

On my main page, I am currently using:

$('#dateStartMainChart').load(url);

to load a php file which outputs:

<script> 
$(function() {
    $( "#dateEndMainChartSelect" ).datepicker({ 
        dateFormat: 'yy-mm-dd',
        defaultDate: -1,
        minDate: new Date(2011,03,03),
        maxDate: +0,
            firstDay: 1,
        changeMonth: true,
        changeYear: true
    });
}); 
</script>
<input type="text" class="text" value=2011-03-04 id="dateEndMainChartSelect" align="center"/>

where the minDate and maxDate have been populated correctly from the mysql database. However, the result is that I just get a text box with the date in it on my main page instead of the datepicker element.

Any thoughts?

解决方案

OK, I finally figured this out. I initially define and use the datepicker as normal. When I need to dynamically update it, I use:

$.getScript('url.php', function() {updateDate(); });

In my case, I use this on change of a select box.

The php file that is called queries a mysql database outputs the following (using echo):

function updateDate() {
        $( "#dateStartMainChartSelect" ).datepicker('change',{ 
            minDate: new Date(2011,01,01),
            maxDate: new Date(2011,02,01)
        });
    }

You can add any of the datepicker options here that you want to change. Thanks to JasCav, I ended up looking in the right places for the solution.

这篇关于日期戳动态最小/最大日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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