【问题标题】:How to get date with datepicker and pass via GET?如何使用 datepicker 获取日期并通过 GET 传递?
【发布时间】:2012-02-09 01:43:37
【问题描述】:

我在通过 GET url 传递日期参数时遇到问题。我从两个与 datepicker 关联的输入字段中获取数据。 这是代码:

$(".options input[type='submit']").click(function() {
    $('#From').datepicker();
    $('#To').datepicker();
    var $From = $('#From').datepicker('getDate').getDate();
    var $To = $('#To').datepicker('getDate').getDate();
    $('#placeholder').html('<img src="php/jpgraph/example2.php?From=' + $From + '&To=' + $To + '" />');
});

HTML页面:

<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <link rel="stylesheet" href="layout.css" type="text/css"/>
        <link rel="stylesheet" href="jquery-ui-1.8.17.custom.css" type="text/css" />
        <script type="text/javascript" src="jquery.js"></script>
        <script type="text/javascript" src="jquery-ui.js"></script>
        <script type="text/javascript" src="newjavascript.js"></script>
    </head>
    <body>
        <div id="container">
            <div id="sidemenu">
                <div class="options">
                    Датум од:<input type="text" id="From" name="From" size="10"/><br />
                    Датум до:<input type="text" id="To" name="To" size="10"/>
                </div>   
                <br />    
                <div class="options">
                    <input type="submit" value="Show">
                </div>
            </div>
            <div id="content">
                <div id="placeholder" style="width:600px;height:300px;"></div>
            </div>
        </div><!-- divContainer --> 
    </body>
</html>

当我从日期选择器图像中选择日期时。但是,如果我不使用 datepicker 选择日期,则不会显示任何内容。也许我可以检查是否没有选择日期,然后将值设置为空字符串。像这样的:

if ($From == null) {
   $From = '';
}
if ($To == null) {
   $To = '';
}

我试过这个,但它不起作用。有什么办法可以解决问题?

编辑:目前,我不在服务器端处理 GET 参数,以简化问题,但请看一下:

<?php
require_once ('jpgraph.php');
require_once ('jpgraph_line.php');

$con = mysql_connect("localhost", "user", "pass");
if (!$con) {
    die('Could not connect:' . mysql_error());
}
mysql_select_db("db", $con);
$result = mysql_query("select Temperature from TEMPERATURE");
$niz = array();
while ($row = mysql_fetch_array($result)) {
    $niz[] = $row['Temperature'];
}

$graph = new Graph(600,400);
$graph->SetScale('intint');
$graph->title->set('Title');
$graph->xaxis->title->Set('Day');
$graph->yaxis->title->Set('Temp');
$lineplot=new LinePlot($niz);
$lineplot->SetColor('blue');
$graph->Add($lineplot);
$graph->Stroke();
?>

【问题讨论】:

  • 需要查看生成图片的代码。
  • 也许你没有处理example2.php上的空值
  • 请同时添加您的 php 代码部分。
  • PHP 在这里无关紧要,因为我不处理服务器端的 GET 参数。无论如何,我发布了代码,所以请看我的编辑。

标签: php jquery datepicker


【解决方案1】:

试试这个。

if($('#From').val()){
   //Get the date here
   var fromDate = $('#From').datepicker('getDate');
}

if($('#To').val()){
   //Get the date here
   var toDate = $('#To').datepicker('getDate');
}

【讨论】:

    猜你喜欢
    • 2012-02-13
    • 2013-11-28
    • 2011-02-03
    • 1970-01-01
    • 1970-01-01
    • 2012-07-16
    • 1970-01-01
    • 2021-01-15
    • 1970-01-01
    相关资源
    最近更新 更多