我使用wordpress,强大的表单和完整的日历来创建定制的日历解决方案
除了我想在日历中每个标题的前面添加一个字体真棒图标外,我还能正常工作。
如果我在标题中添加任何html,如下面的代码,我只看到打印的代码,而不是最终的结果。
$('#calendar').fullCalendar({
events: [
{
title : '<i class="fa fa-asterisk"></i>event1',
start : '2010-01-01'
},
{
title : 'event2',
start : '2010-01-05',
end : '2010-01-07'
},
{
title : 'event3',
start : '2010-01-09T12:30:00',
allDay : false // will make the time show
}
]
});
&#13;
你们有没有人指出我正确的方向? : - )
此致
马特
答案 0 :(得分:31)
您可以在eventRender功能中修改标题前置字体 - 真棒图标。
我添加了一个带有关键图标的选项:如果定义了图标,则在eventRender函数中添加fontawesome图标。
检查此示例:
$('#calendar').fullCalendar({
events: [
{
title : 'event1',
start : '2015-10-01',
icon : "asterisk" // Add here your icon name
},
{
title : 'event2',
start : '2015-10-05',
end : '2015-10-07'
},
{
title : 'event3',
start : '2015-10-09T12:30:00',
allDay : false // will make the time show
}
],
eventRender: function(event, element) {
if(event.icon){
element.find(".fc-title").prepend("<i class='fa fa-"+event.icon+"'></i>");
}
}
})
答案 1 :(得分:4)
完整日历4.4出现相同的问题。 我尝试使用S.Poppic中的代码
eventRender: function (info) {
let icon = info.event.extendedProps.icon;
let title = $(info.el).first('.fc-title-wrap');
if (icon !== undefined) {
title.prepend("<i class='" + info.event.extendedProps.icon + "'></i>");
}
}
它有一个小问题:.fc-title-wrap删除了“时间”
然后我从这里看到另一个答案,指向类'.fc-title',它可以工作,但不适用于FullCalendar 4.4中的列表视图
我使用了以下代码,它对我来说适用:月视图,周视图,日视图和列表视图。
如您所见,它基于我在这里找到的一些答案。 希望对您有所帮助。
eventRender: function (info) {
let icon = info.event.extendedProps.icon;
// this works for Month, Week and Day views
let title = $(info.el).find('.fc-title');
// and this is for List view
let title_list = $(info.el).find('.fc-list-item-title a');
if (icon) {
var micon = "<i class='" + icon + "'></i> ";
title.prepend(micon);
title_list.prepend(micon);
}
}
答案 2 :(得分:3)
FullCalendar 4.3.1出现了相同的问题。希望对您有所帮助。
eventRender: function (info) {
let icon = info.event.extendedProps.icon;
let title = $(info.el).first('.fc-title-wrap');
if (icon !== undefined) {
title.prepend("<i class='" + info.event.extendedProps.icon + "'></i>");
}
}
答案 3 :(得分:1)
如果您想用图标替换文本,可以使用下面的代码
eventRender: function(event, element) {
element.find(".fc-title").html(function () { return $(this).html().replace("Rs", "<i class='fa fa-inr'></i>")});
}
答案 4 :(得分:1)
使用全日历V4,我的渲染看起来像这样
以$ ICON作为占位符的json标题:
{
start: date
title: '$ICON custom_name'
img: 'fontawesome-icon-name'
}
eventRender: function(info) {
info.el.innerHTML = info.el.innerHTML.replace('$ICON', "<em class='far fa-"+info.event.extendedProps.img+"'></em>");
}
欢呼 汉尼斯
答案 5 :(得分:1)
您可以在全日历标题中添加超棒的字体图标作为CSS内容(:在伪元素之前)
.fc-title:before {
font-family: "Font Awesome 5 Free";
content: "\f274";
display: inline-block;
padding-right: 3px;
font-weight: 900;
}
根据您的要求添加CSS内容,当前使用fa-calendar-check
图标内容。
您可以将font-family
更改为Font Awesome 5 Brands
或Font Awesome 5 Free