从日历日期选择器获取选定日期 [英] Getting selected date from calendar date picker

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

问题描述

我需要帮助从日历日期选择器获取选定的日期。目前我可以选择日期(从...到...),并将其放入文本框。但我无法得到要放入PHP变量的值。

I need help with getting the selected date from calendar date picker. Currently I can select the date(from...to...) and place it into textbox. But I cannot get the value to put into PHP variable.

<head>


    <meta charset="utf-8" />
    <title>jQuery UI Datepicker - Select a Date Range</title>
    <link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
    <script src="http://code.jquery.com/jquery-1.9.1.js"></script>
    <script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
    <link rel="stylesheet" href="/resources/demos/style.css" />
    <script>
        $(function() {
            $( "#from" ).datepicker({
                defaultDate: "+1w",
                changeMonth: true,
                numberOfMonths: 3,
                onClose: function( selectedDate ) {
                    $( "#to" ).datepicker( "option", "minDate", selectedDate );
                }
            });
            $( "#to" ).datepicker({
                defaultDate: "+1w",
                changeMonth: true,
                numberOfMonths: 3,
                onClose: function( selectedDate ) {
                    $( "#from" ).datepicker( "option", "maxDate", selectedDate );
                }
            });


        });
    </script>
</head>
<body>


        <label for="from">From</label>
        <input type="text" id="from" name="from" />


        <label for="to">to</label>
        <input type="text" id="to" name="to" />

</body>


推荐答案

您尚未提交表单。您应该先创建表单,如下所示:

You haven't got a form to submit. You should create a form first, like so:

<form action="foo.php" method="post">

    <label for="from">From</label>
    <input type="text" id="from" name="from" />


    <label for="to">to</label>
    <input type="text" id="to" name="to" />

    <input type="submit" value="Submit dates">
</form>

在服务器端,如果您通过POST提交表单),您可以从PHP $ _POST变量获取日期:

And on the server side, if you're submitting the form via POST (as in the example above), you can obtain the dates from the PHP $_POST variable:

$from = $_POST['from'];
$to = $_POST['to'];

这篇关于从日历日期选择器获取选定日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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