鼠标事件之 eventClick – FullCalendar 中文文档
2014-02-13 · 269 chars · 2 min read
当用户点击某个日程(或者叫事件)的时候触发 eventClick 回调:
function( event, jsEvent, view ) { }
event 是 Event Object 对象,包含了日程的信息(例如日期,标题等)
jsEvent 是原生的 javascript 事件,包含“点击坐标”之类的信息。
view 是当前的 View Object 。
在 eventClick 回调函数内部,this 是当前点击那个日程的<div>,示例:
$('#calendar').fullCalendar({
eventClick: function (calEvent, jsEvent, view) {
alert('Event: ' + calEvent.title)
alert('Coordinates: ' + jsEvent.pageX + ',' + jsEvent.pageY)
alert('View: ' + view.name)
// change the border color just for fun
$(this).css('border-color', 'red')
},
})
通常情况下,如果日程的 Event Object 对象含有 url 属性,点击这个日程会跳转到这个 url,在 eventClick 函数中 return false 会阻止 url 的访问。
下例演示在新窗口中打开 url:
$('#calendar').fullCalendar({
events: [
{
title: 'My Event',
start: '2010-01-01',
url: 'http://google.com/',
},
// other events here
],
eventClick: function (event) {
if (event.url) {
window.open(event.url)
return false
}
},
})
官方英文文档:http://arshaw.com/fullcalendar/docs/mouse/eventClick/


