1

我在 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

获取数据.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);
?>
4

4 回答 4

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>   
于 2013-06-21T10:24:38.813 回答
0

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

function onSelect(date){ 
                $('#result').text(date.getFullYear() + '-' + date.getMonth() + '-' + date.getDate());       
} 
于 2013-06-21T04:42:38.107 回答
0

您还可以使用strftime()strtotime()更改 php 中的格式:

$created = isset($_POST['text']) ? strftime('%Y-%m-%d', strtotime(mysql_real_escape_string($_POST['text']))) : '';
于 2014-02-13T12:21:44.040 回答
0

示例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>   
于 2015-09-17T14:19:18.830 回答