简体   繁体   English

使用Datepicker进行jQuery

[英]Using Datepicker for a jquery

I'm trying to have a date selection with datepicker, and then use this date for a query. 我正在尝试使用datepicker进行日期选择,然后将该日期用于查询。 I have a Movements table, and even if I select a date with an entry, the result is always 0. 我有一个“移动”表,即使选择带条目的日期,结果也始终为0。

How do I fix that ? 我该如何解决?

<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.0/themes/base/jquery-ui.css" />
<script src="http://code.jquery.com/jquery-1.8.3.js"></script>
<script src="http://code.jquery.com/ui/1.10.0/jquery-ui.js"></script>
<link rel="stylesheet" href="/resources/demos/style.css" />
<script>
$(function() {
                $( "#datepicker" ).datepicker();
             });
</script>
</head>
<body>
<p>Date: <input type="text" id="datepicker" /> 
<p id="result"> Turnover: </p>
    <script>
    $("input").change(function(){
        var currentDate = $( "#datepicker" ).datepicker( "getDate" );
        document.getElementById("result").innerHTML= <%= Movement.where(:movementDate =>("currentDate")).sum("turnover")%>;
    });
    </script>
</p>
</body>

Sorry, but this is all wrong. 抱歉,这全都错了。

You need to send the date to your server via ajax, so that it can execute the query with the given date and then send the result back to the frontend. 您需要通过ajax将日期发送到服务器,以便它可以使用给定的日期执行查询,然后将结果发送回前端。

In case you have, go here and have a look at jQuery and ajax requests: http://api.jquery.com/category/ajax/ 如果有的话,请转到此处查看jQuery和ajax请求: http : //api.jquery.com/category/ajax/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM