根据javascript或jquery中的选定日期来禁用datepicker的先前日期 [英] Disable previous dates of a datepicker according to selected date in javascript or jquery

查看:143
本文介绍了根据javascript或jquery中的选定日期来禁用datepicker的先前日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个datepickers如startdate和enddate.If我选择2015年6月18日在startdate我必须禁用datepicker以前的日期到18thjune2015在enddate。

I have two datepickers like startdate and enddate.If i select 18th june 2015 in startdate i have to disable previous dates in datepicker to 18thjune2015 in enddate.

这里是我的代码。

 $("#txtstartdate").datepicker({ minDate: 0 });

对于结束日期:

    var startdate = $("#txtstartdate").val();
    $("#txtenddate").datepicker({ minDate: startdate }); 

它不工作。任何人都可以帮助我。
谢谢。

Its not working. Can anyone pls help me on this. thank you.

推荐答案

您需要使用选项方法在更改开始日期时设置

You need to set it using the option method on change of start date

$("#txtstartdate").datepicker({
  minDate: 0,
  onSelect: function(date) {
    $("#txtenddate").datepicker('option', 'minDate', date);
  }
});

$("#txtenddate").datepicker({});

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.js"></script>
<link rel="stylesheet" type="text/css" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.4/themes/redmond/jquery-ui.css">
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.4/jquery-ui.js"></script>

<input id="txtstartdate" />
<input id="txtenddate" />

这篇关于根据javascript或jquery中的选定日期来禁用datepicker的先前日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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