Javascript 日期选择器在窗体重新加载后显示所选值

Javascript 日期选择器在窗体重新加载后显示所选值,javascript,php,jquery,datepicker,Javascript,Php,Jquery,Datepicker,我在表单中有一个jquery日期选择器输入。它将当前日期正确显示为初始值。我希望此日期选择器显示提交表单后重新加载页面时选择的日期。但现在,我只知道如何在value属性中回显当前日期 以下是AppointmentDateSelector.php中的datepicker表单: <form method="POST"> <div style='margin:0 auto; text-align:center;'> <label>Appoin

我在表单中有一个jquery日期选择器输入。它将当前日期正确显示为初始值。我希望此日期选择器显示提交表单后重新加载页面时选择的日期。但现在,我只知道如何在value属性中回显当前日期

以下是AppointmentDateSelector.php中的datepicker表单:

<form method="POST">
    <div style='margin:0 auto; text-align:center;'>
        <label>Appointment Date: </label>
        <input type="text" id="datepicker" name="date" value=<?php echo date('m/d/Y');?> />
        <input type="hidden" name="action" value="list_appointments"/>
        <input type="hidden" name="date" value="Value of datepicker goes here?"/>
        <input type="submit" value="Refresh List" name="Update" />
        <br />
    </div>
</form>
以及包含它的Scheduling.php页面

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title></title>
    <!-- for datepicker -->
    <link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.17/themes/base/jquery-ui.css" rel="stylesheet" type="text/css" />
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
    <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.17/jquery-ui.min.js"></script>
    <!-- for timepicker -->
    <script src="//cdnjs.cloudflare.com/ajax/libs/timepicker/1.3.5/jquery.timepicker.min.js"></script>
    <link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/timepicker/1.3.5/jquery.timepicker.min.css">
    <script type="text/javascript">   
        $(document).ready(function(){
            $( "#datepicker" ).datepicker({minDate:'0',
            beforeShowDay:
                  function(dt)
                  {
                    return [dt.getDay() === 2 || dt.getDay() === 3, ""];
                  }});
            });
        $(document).ready(function(){
            $('input.timepicker').timepicker({
                timeFormat: 'h:mm p',
                interval: 30,
                minTime: '9',
                maxTime: '5:00pm',
                defaultTime: '9',
                startTime: '9:00',
                dynamic: false,
                dropdown: true,
                scrollbar: true                
            });
        });
    </script>  
</head>
<body>
    <?php 
    include('AppointmentDateSelector.php');

    // determine if we got a INPUT_POST or INPUT_GET...
    // if both NULL, then should default to 'list_appointments'
    $action = filter_input(INPUT_POST, 'action');   
    if ($action == NULL) 
    {
        $action = filter_input(INPUT_GET, 'action');
        if ($action == NULL) {
            $action = 'list_appointments'; 
        }
    }

    if ($action == 'list_appointments') 
    {
        $date = filter_input(INPUT_POST, 'date');

        $dateparse = date_parse($date); 
        #var_dump($dateparse);
        if (checkdate($dateparse['month'], $dateparse['day'], $dateparse['year'])) 
        {       
            // Get Appointment data
            $appointments = get_appointments($date);
            //header("Location: ./Scheduling.php?date=$date");

            // displays list of appointments on that date
            include('AppointmentList.php');
        }
        else
        {
            //Raise an error that says invalid date.
        }
    }               
    ?>
</body>
</html>

您需要检查是否提交了日期,在这种情况下,将其用作值:

<input type="text" id="datepicker" name="date" value="<?php echo (isset($_POST['date']) ? $_POST['date'] : date('m/d/Y')); ?>" />

您需要将拾取的日期传递到值属性中,每次都传递当前值。提交表单后,获取新值,您可以尝试以下代码:var setDate=new date your date Variable here;setDate=$.datepicker.formatDateyy-mm-dd,setDate;//如果需要,请更改格式$input.timepicker.valsetDate@Vigneshvaidyana那么该代码应该插入到哪里?当使用该代码进行输入时,该代码最终会单独打印到输入的右侧:value=当前日期此处单独的日期是如何格式化的?您认为我们是否需要将-替换为/以匹配今天的日期格式?显示正确的日期时,日期格式正确。但是,它显示在文本框的右侧,好像编译器思想值=m/d/y不是它需要考虑的一个HTML元素来确定它的默认显示值。