试图让dayClick()
回调获得当前日期。相反,无论我做什么,似乎return YESTERDAY
甚至显示一周中错误的一天(即当匹配日期的实际日期是星期六时它会说“星期五”)。一个非常奇怪的事情是,当我点击"today"
周围的日期(即突出显示的日期)时,这似乎只会发生,有时它会自行纠正,其他时候......不是。
这是我的JS:
(function() {
'use strict';
$(document).ready(function(){
// Full calendar
$('#calendar').fullCalendar({
header: {
left: '',
center: 'title',
right: ''
},
dayClick: function(date) {
console.log(date);
}
});
});
})();
我的HTML:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<title>VetPro Dashboard</title>
<!-- Style Css-->
<link rel="stylesheet" href="../../vendor/bower_components/fullcalendar/dist/fullcalendar.min.css">
<!-- jQuery -->
<script type="text/javascript" src="../../vendor/bower_components/jquery/dist/jquery.min.js"></script>
<script type="text/javascript" src="../../vendor/bower_components/moment/min/moment.min.js"></script>
<script type="text/javascript" src="../../vendor/bower_components/fullcalendar/dist/fullcalendar.min.js"></script>
<script type="text/javascript" src="../../assets/javascripts/calendar_scheduler.js"></script>
</head>
<body class="split-background">
<!-- Start Body -->
<div class="container-fluid" id="vetpro-dashboard">
<h1 class="page-header text-center">Dashboard</h1>
<div class="container">
<ul id="tabs" class="text-center col-xs-12 font-mobile-17">
<a href="dashboard_projects.html"><li class="col-xs-2">Projects</li></a>
<li class="col-xs-2 active">Schedule</li>
<a href="dashboard_transactions.html"><li class="col-xs-2">Transactions</li></a>
<a href="dashboard_profile.html"><li class="col-xs-2">Profile</li></a>
<a href="#"><li class="col-xs-2">Support</li></a>
</ul>
</div>
<div class="container container-border" id="dashboard-schedule">
<div class="col-md-6">
<div id="calendar">
</div>
</div>
<div class="col-md-6" id="exceptions">
<div id="scheduler">
<div id="timepicker">
</div>
</div>
</div>
</div>
</div>
<!-- End Body -->
</body>
</html>
最后,当我点击12/4/15(此帖子的日期)时显示的控制台日志:
n {_isAMomentObject: true, _isUTC: true, _offset: 0, _locale: R.b, _d: Thu Dec 03 2015 16:00:00 GMT-0800 (Pacific Standard Time)…}
这有什么不对?我可以采取哪些措施来确保将来不会发生这种情况?谢谢!
试试这个:
dayClick: function(date, jsEvent, view) {
date.format();
}
您可以使用以下方法获取日期: -
dayClick: function(date, jsEvent, view) {
alert('Clicked on: ' + date.format());
alert('Coordinates: ' + jsEvent.pageX + ',' + jsEvent.pageY);
alert('Current view: ' + view.name);
}
在jquery fullcalendar中,您将获得上一个日期,您必须在该日期执行某些过程。
出于某种原因,在标题中添加“next”和“prev”按钮可以解决问题。不知道为什么。希望这可以帮助其他人在将来遇到这个问题。
“我修好了”:
var startdate = moment( date['date'] );
startdate = startdate.subtract(1, "days");
this.dia = startdate.subtract(-1, "days").toString(); // <-- correct date