javascript-Fullcalendar(v2.x)从eventClick获取日单元吗?
作者:互联网
我正在努力获取点击多天(期间)事件(eventClick)时所点击的日期.
点击背景单元格,很简单:
function dayClick(date, jsEvent, view) {
//todo: store related day
$scope.selectedDay = date;
}
但是,当单击某个事件(为期数天)时,我无法检索到用户确切在哪一天. (我需要根据背景天执行其他操作):
function alertEventOnClick(event, jsEvent, view) {
// "event" stores only start and end date without any reference to the current day
// "jsEvent" retrieve the "td" element but fullcalendar HTML structure is complex and it's impossible to go-up to find the day-cell
// $scope.selectedDay = ??
};
我尝试玩“ selectable”,但“ eventClick” JS事件不会传播,也不会“选择”当天
谢谢
解决方法:
如果您根本不需要捕获事件点击,则只需将一个类添加到具有指针事件的所有事件即可:
eventRender: function (event, element) {
$(element).addClass('clickThrough');
},
IE8
eh有一种破解指针事件的方法:在IE8上,但是在尝试实现它时,我发现了实现目标的更简单方法. (模拟的指针事件黑客描述为here.)
要获取光标处的日期:
>隐藏事件表
>在光标下获取元素
>显示事件表
eventClick: function (calEvent, jsEvent, view) {
var topLayer = $(jsEvent.currentTarget).closest("tbody");
topLayer.hide(); //hide the entire event layer (makes it work with multiple events)
var dayElement = document.elementFromPoint(jsEvent.pageX, jsEvent.pageY); //get the element under the cursor (should be a day cell)
topLayer.show();
alert($(dayElement).data("date"));
}
更好的IE8解决方法
(这似乎不起作用)
因此,事实证明锚标记具有更好的指针事件:解决方法. https://stackoverflow.com/a/18118092/728393
您只需将属性disable =“ disabled”添加到< a>可以单击它.
eventRender: function (event, element) {
$(element).addClass('clickThrough').attr("disabled","disabled"); //disabled attribute is a IE workaround for pointer-events
},
标签:fullcalendar,events,javascript 来源: https://codeday.me/bug/20191028/1954692.html