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

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

问题描述

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

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.

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

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);

加载一个输出的php文件:

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"/>

其中 minDate 和 maxDate 已从 mysql 数据库正确填充.然而,结果是我只在主页上得到一个带有日期的文本框,而不是日期选择器元素.

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.

有什么想法吗?

推荐答案

好的,我终于想通了.我最初像往常一样定义和使用日期选择器.当我需要动态更新它时,我使用:

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.

调用mysql数据库的php文件输出如下(使用echo):

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)
        });
    }

您可以在此处添加要更改的任何日期选择器选项.感谢 JasCav,我最终找到了正确的解决方案.

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天全站免登陆