【问题标题】:jQuery easyui datebox event to querying mysqljQuery easyui datebox 事件查询 mysql
【发布时间】:2013-06-20 23:37:55
【问题描述】:

我在 jQuery easyui datebox 上使用这个脚本

<script> 
        function onSelect(date){ 
            $('#result').text(date)       
        } 

</script> 

输出是

Selected Date: Tue Jun 11 2013 00:00:00 GMT+0800 (China Standard Time)

那么,是否可以进行输出:

2013-06-11

如何制作?

因为我想将值 datebox 事件传递给查询 mysql

getdata.php

<?php
include 'db.php';

   $created = isset($_POST['text']) ? mysql_real_escape_string($_POST['text']) : '';

$where = "datetime LIKE '$created%'";
$rs = mysql_query("select * from fe1a where " . $where );

$result = array();
while($row = mysql_fetch_object($rs)){
    array_push($array, $row);
}


echo json_encode($result);
?>

【问题讨论】:

    标签: php jquery mysql jquery-easyui datebox


    【解决方案1】:

    工作示例:http://jsfiddle.net/Gajotres/xV9BZ/

    Javascript:

    $('.easyui-datebox').datebox({
        onSelect: function(date){
            alert(date.getFullYear()+"-"+(date.getMonth()+1)+"-"+date.getDate());
        }
    });
    

    或者在你的情况下是:

    $('.easyui-datebox').datebox({
        onSelect: function(date){
            $('#result').text(date.getFullYear()+"-"+(date.getMonth()+1)+"-"+date.getDate());
        }
    });
    

    HTML:

    <!DOCTYPE html>
    <html>
        <head>
            <title>jQM Complex Demo</title>
            <meta http-equiv='Content-Type' content='text/html; charset=utf-8'/>
            <meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0; minimum-scale=1.0; user-scalable=no; target-densityDpi=device-dpi"/>
            <link rel="stylesheet" href="http://www.jeasyui.com/easyui/themes/default/easyui.css" />
            <script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
            <script src="http://www.jeasyui.com/easyui/jquery.easyui.min.js"></script>    
        </head>
        <body>
            <input class="easyui-datebox"></input>  
        </body>
    </html>   
    

    【讨论】:

      【解决方案2】:

      这样的事情应该可以解决问题:

      function onSelect(date){ 
                      $('#result').text(date.getFullYear() + '-' + date.getMonth() + '-' + date.getDate());       
      } 
      

      【讨论】:

        【解决方案3】:

        你也可以用strftime()strtotime()来改变php中的格式:

        $created = isset($_POST['text']) ? strftime('%Y-%m-%d', strtotime(mysql_real_escape_string($_POST['text']))) : '';
        

        【讨论】:

        • Date-object 的使用与 tric. $date = new DateTime($_POST['text']); $date = $date-&gt;format(Y-m-d');
        【解决方案4】:

        例如http://jsfiddle.net/vwhy1fnm/1/

        Javascript:

        将此用于输出 (2015-01-01)。

        var result;
        $('.easyui-datebox').datebox({
            onSelect: function (date) {
                var y = date.getFullYear();
                var m = date.getMonth() + 1;
                var d = date.getDate();
                result = (y + '-' + (m < 10 ? ('0' + m) : m) + '-' + (d < 10 ? ('0' + d) : d));
                alert(result);//<--alert for example you can remove this
            }
        });
        

        HTML:

        <!DOCTYPE html>
        <html>
            <head>
                <title>jQM Complex Demo</title>
                <meta http-equiv='Content-Type' content='text/html; charset=utf-8'/>
                <meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0; minimum-scale=1.0; user-scalable=no; target-densityDpi=device-dpi"/>
                <link rel="stylesheet" href="http://www.jeasyui.com/easyui/themes/default/easyui.css" />
                <script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
                <script src="http://www.jeasyui.com/easyui/jquery.easyui.min.js"></script>    
            </head>
            <body>
                <input class="easyui-datebox"></input>  
            </body>
        </html>   
        

        【讨论】:

          猜你喜欢
          • 2017-01-24
          • 2014-03-21
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2015-05-06
          • 1970-01-01
          • 1970-01-01
          • 2014-08-08
          相关资源
          最近更新 更多