我在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);
?>
答案 0 :(得分:1)
工作示例:http://jsfiddle.net/Gajotres/xV9BZ/
$('.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>
答案 1 :(得分:0)
这样的事情可以解决问题:
function onSelect(date){
$('#result').text(date.getFullYear() + '-' + date.getMonth() + '-' + date.getDate());
}
答案 2 :(得分:0)
您还可以使用 strftime()和 strtotime()更改php中的格式:
$created = isset($_POST['text']) ? strftime('%Y-%m-%d', strtotime(mysql_real_escape_string($_POST['text']))) : '';
答案 3 :(得分:0)
示例http://jsfiddle.net/vwhy1fnm/1/
将此用于输出(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
}
});
<!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>