javascript - 如何显示带有链接的资源标题?
问题描述
我正在使用 FullCalendar 开发一个 Web 系统。
我正在尝试使用链接自定义该资源标题,就像使用 eventClick 一样,但我自定义的代码无法按预期工作。
有人可以帮忙解决这个案子吗?
先感谢您。
原始代码
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8'/>
<style>
html, body {
margin: 0;
padding: 0;
font-family: Arial, Helvetica Neue, Helvetica, sans-serif;
font-size: 14px;
}
#calendar {
max-width: 900px;
margin: 40px auto;
}
</style>
<link href='https://unpkg.com/@fullcalendar/core@4.4.0/main.min.css' rel='stylesheet'/>
<link href='https://unpkg.com/@fullcalendar/timeline@4.4.0/main.min.css' rel='stylesheet'/>
<link href='https://unpkg.com/@fullcalendar/resource-timeline@4.4.0/main.min.css' rel='stylesheet'/>
<script src='https://unpkg.com/@fullcalendar/core@4.4.0/main.min.js'></script>
<script src='https://unpkg.com/@fullcalendar/timeline@4.4.0/main.min.js'></script>
<script src='https://unpkg.com/@fullcalendar/resource-common@4.4.0/main.min.js'></script>
<script src='https://unpkg.com/@fullcalendar/resource-timeline@4.4.0/main.min.js'></script>
<script>
document.addEventListener('DOMContentLoaded', function () {
var calendarEl = document.getElementById('calendar');
var calendar = new FullCalendar.Calendar(calendarEl, {
plugins: ['resourceTimeline'],
defaultView: 'resourceTimelineDay',
header: {
left: 'prev,next',
center: 'title',
right: 'resourceTimelineDay,resourceTimelineWeek,resourceTimelineMonth'
},
resourceLabelText: 'Rooms',
resources: [
{id: 'a',
title: 'room1',
url: 'http://google.com/'
},
],
});
calendar.render();
});
</script>
</head>
<body>
<div id='calendar'></div>
</body>
</html>
我添加引用 eventClick 的代码
resourceClick: function (info) {
info.jsResource.preventDefault();
if (info.resource.url) {
window.open(info.resource.url);
}
},
我也尝试过使用下面的资源渲染,但它不起作用......
resources: [
{
id: 'a',
title: '<a href="http://google.com/">room1</a>',
},
],
resourceRender: function (renderInfo,element) {
element.find('span.fc-title').html(element.find('span.fc-title').text());
}
我的开发环境
- HTML 5
- 完整日历:v4
解决方案
这是我对问题的解决方案:
resourceRender: function (resourceObj, $th) {
$th.html(
$('<a href="http://google.com/">' + resourceObj.title + '</a>')
);
},
推荐阅读
- c++ - 获取系统 TEMP 变量的路径
- azure-devops-migration-tools - Azure DevOps 迁移工具能否用于备份 Boards 项目的工作项?
- python - 使用 gspread_pandas 导入 google sheet 时如何指定数据类型?
- c - 将汇编语言函数调用到 ac 程序中
- c++ - 推断成员变量类型
- javascript - 使用 react-hook-form 将输入框中的值从字符串转换为数组
- python - 从单个列中的 Pandas 数据框在 SQL 中创建大型“In”语句
- css - 对图像做出响应
- azure-devops - 通过 Azure DevOps REST API 获取 PR 代码覆盖率差异状态
- java - 它是如何工作的,当我总是打开应用程序时,它会运行该方法,而不仅仅是在我单击运行时?