jquery中的datatimepicker指定日期范围

在jquery ui中的日历控件,有时需要用户选择某个日期范围,比如选定某天后,就只能给7天后或者N天后的日期范围给用户选择,这时可以这样做:
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title></title>
    <link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.6/themes/base/jquery-ui.css"
        type="text/css" media="all" />
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js" type="text/javascript"></script>
    <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.6/jquery-ui.min.js"
        type="text/javascript"></script>
    <script type="text/javascript">
        $(function () {

            var txtStartDate = $('#<%= txtStartDate.ClientID  %>');
            var txtEndDate = $('#<%= txtEndDate.ClientID  %>');

            txtStartDate.datepicker({ onClose: clearEndDate });
            txtEndDate.datepicker({ beforeShow: setRange });

            function setRange() {
                var minDate = txtStartDate.datepicker('getDate');
                var maxDate = txtStartDate.datepicker('getDate');
                maxDate.setDate(maxDate.getDate() + 7);
                return {
                    minDate: minDate,
                    maxDate: maxDate
                }
            }

            //Clears the end date textbox
            function clearEndDate(dateText, inst) {
                txtEndDate.val('');
            }
        });

    </script>
</head>
<body>
    <form id="form1" runat="server">
    Start Date:
    <asp:TextBox ID="txtStartDate" runat="server"></asp:TextBox>
       End Date:
    <asp:TextBox ID="txtEndDate" runat="server"></asp:TextBox>

    </form>
</body>
</html>

你可能感兴趣的:(jquery,UI)