我正在尝试在网站上实现bootstrap-year-calendar,但是在JavaScript
功能以及日历在我的网站上的显示方式上遇到了一些麻烦。
我想水平显示日历,就像前面链接中显示的示例一样,但是我只能垂直显示日历,所以我需要向下滚动才能看到几个月;
检查其在我的网站上的显示方式。
我遇到的另一个麻烦是创建新事件时,当我尝试选择一个日期时,它给了我这个错误:
此外,当尝试更新或删除现有事件时,js可以工作,但是什么也不做。
您可以在此处查看我所有的html:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="description" content="">
<meta name="author" content="">
<title>BIMMS - Homepage</title>
<!-- Bootstrap core CSS-->
<link href="vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet">
<!-- Custom fonts for this template-->
<link href="vendor/fontawesome-free/css/all.min.css" rel="stylesheet" type="text/css">
<!-- Page level plugin CSS-->
<link href="vendor/datatables/dataTables.bootstrap4.css" rel="stylesheet">
<!-- Custom styles for this template-->
<link rel="stylesheet" href="http://code.jquery.com/ui/1.9.0/themes/base/jquery-ui.css" />
<link href="css/sb-admin.css" rel="stylesheet">
<link rel="stylesheet" href="vendor/bootstrap-year-calendar/bootstrap-year-calendar.css">
<link rel="stylesheet" href="vendor/bootstrap-year-calendar/bootstrap-year-calendar.min.css">
<script src="vendor/chart.js/Chart.min.js"></script>
<script src='vendor/fullcalendar/moment.min.js'></script>
<script src='vendor/fullcalendar/jquery.min.js'></script>
<script src="vendor/bootstrap-year-calendar/bootstrap-year-calendar.js"></script>
<script src="vendor/bootstrap-year-calendar/bootstrap-year-calendar.min.js"></script>
<script src="js/calendar.js"></script>
</head>
<body id="page-top">
<nav class="navbar navbar-expand navbar-light static-top" style="background-color:#e9ecef;">
<a class="navbar-brand mr-1" href="index.html"><img src="img/bimms.png" width="190" class="d-inline-block align-top"></a>
<button class="btn btn-link btn-sm text-black-50 order-1 order-sm-0" id="sidebarToggle" href="#">
<i class="fas fa-bars"></i>
</button>
<!-- Navbar Search -->
<form class="d-none d-md-inline-block form-inline ml-auto mr-0 mr-md-3 my-2 my-md-0">
<div class="input-group">
<input type="text" class="form-control" placeholder="Search for..." aria-label="Search" aria-describedby="basic-addon2">
<div class="input-group-append">
<button class="btn btn-outline-secondary my-2 my-sm-0" type="button">
<i class="fas fa-search"></i>
</button>
</div>
</div>
</form>
<!-- Navbar -->
<ul class="navbar-nav ml-auto ml-md-0">
<li class="nav-item dropdown no-arrow mx-1">
<a class="nav-link dropdown-toggle" href="#" id="alertsDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<i class="fas fa-bell fa-fw"></i>
<span class="badge badge-danger">9+</span>
</a>
<div class="dropdown-menu dropdown-menu-right" aria-labelledby="alertsDropdown">
<a class="dropdown-item" href="#">Action</a>
<a class="dropdown-item" href="#">Another action</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item" href="#">Something else here</a>
</div>
</li>
<li class="nav-item dropdown no-arrow mx-1">
<a class="nav-link dropdown-toggle" href="#" id="messagesDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<i class="fas fa-envelope fa-fw"></i>
<span class="badge badge-danger">7</span>
</a>
<div class="dropdown-menu dropdown-menu-right" aria-labelledby="messagesDropdown">
<a class="dropdown-item" href="#">Action</a>
<a class="dropdown-item" href="#">Another action</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item" href="#">Something else here</a>
</div>
</li>
<li class="nav-item dropdown no-arrow">
<a class="nav-link dropdown-toggle" href="#" id="userDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<i class="fas fa-user-circle fa-fw"></i>
</a>
<div class="dropdown-menu dropdown-menu-right" aria-labelledby="userDropdown">
<a class="dropdown-item" href="usersettings.html">Settings</a>
<a class="dropdown-item" href="#">Activity Log</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item" href="#" data-toggle="modal" data-target="#logoutModal">Logout</a>
</div>
</li>
</ul>
</nav>
<div id="wrapper">
<!-- Sidebar -->
<ul class="sidebar navbar-nav">
<li class="nav-item">
<a class="nav-link" href="loggedin.html">
<i class="fas fa-fw fa-tachometer-alt"></i>
<span>Dashboard</span>
</a>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="pagesDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<i class="fas fa-fw fa-folder"></i>
<span>Projects</span>
</a>
<div class="dropdown-menu" aria-labelledby="pagesDropdown">
<h6 class="dropdown-header">Active Projects</h6>
<a class="dropdown-item" href="project.html">Data Center</a>
<a class="dropdown-item" href="#">Ulster University</a>
<div class="dropdown-divider"></div>
<h6 class="dropdown-header">Manage Projects</h6>
<a class="dropdown-item" href="newproject.html">New Project</a>
<a class="dropdown-item" href="newsubproject.html">New Sub-project</a>
<a class="dropdown-item" href="#">Edit Project</a>
</div>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="pagesDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<i class="fas fa-fw fa-chart-area"></i>
<span>Project Analysis</span>
</a>
<div class="dropdown-menu" aria-labelledby="pagesDropdown">
<h6 class="dropdown-header">Active Projects</h6>
<a class="dropdown-item" href="charts.html">Data Center</a>
<a class="dropdown-item" href="#">Ulster University</a>
</div>
</li>
<li class="nav-item">
<a class="nav-link" href="tables.html">
<i class="fas fa-fw fa-database"></i>
<span>Database</span></a>
</li>
<li class="nav-item active">
<a class="nav-link" href="tasks.html">
<i class="fas fa-fw fa-tasks"></i>
<span>Tasks</span></a>
</li>
<li class="nav-item active">
<a class="nav-link" href="calendar.html">
<i class="fas fa-fw fa-calendar"></i>
<span>Calendar</span></a>
</li>
</ul>
<div id="content-wrapper">
<div class="container-fluid">
<!-- Breadcrumbs-->
<ol class="breadcrumb">
<li class="breadcrumb-item">
<a href="#">Dashboard</a>
</li>
<li class="breadcrumb-item active">Calendar</li>
</ol>
<!--Content-->
<div class="container">
<div class='calendar' id="calendar"></div>
</div>
<!-- Sticky Footer -->
<footer class="sticky-footer">
<div class="container my-auto">
<div class="copyright text-center my-auto">
<span>Copyright © BIMMS 2018</span>
</div>
</div>
</footer>
</div>
<!-- /.content-wrapper -->
</div>
<!-- /#wrapper -->
<!-- Scroll to Top Button-->
<a class="scroll-to-top rounded" href="#page-top">
<i class="fas fa-angle-up"></i>
</a>
<!-- Logout Modal-->
<div class="modal fade" id="logoutModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Ready to Leave?</h5>
<button class="close" type="button" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">Select "Logout" below if you are ready to end your current session.</div>
<div class="modal-footer">
<button class="btn btn-secondary" type="button" data-dismiss="modal">Cancel</button>
<a class="btn btn-primary" href="login.html">Logout</a>
</div>
</div>
</div>
</div>
<!-- Bootstrap core JavaScript-->
<script src="vendor/bootstrap/js/bootstrap.bundle.min.js"></script>
<!-- Core plugin JavaScript-->
<script src="vendor/jquery-easing/jquery.easing.min.js"></script>
<!-- Page level plugin JavaScript-->
<script src="vendor/datatables/jquery.dataTables.js"></script>
<script src="vendor/datatables/dataTables.bootstrap4.js"></script>
<!-- Custom scripts for all pages-->
<script src="js/sb-admin.min.js"></script>
<!-- Demo scripts for this page-->
<script src="js/demo/datatables-demo.js"></script>
<script src="js/demo/chart-area-demo.js"></script>
</body>
</html>
还有日历js文件:
function editEvent(event) {
$('#event-modal input[name="event-index"]').val(event ? event.id : '');
$('#event-modal input[name="event-name"]').val(event ? event.name : '');
$('#event-modal input[name="event-location"]').val(event ? event.location : '');
$('#event-modal input[name="event-start-date"]').datepicker('update', event ? event.startDate : '');
$('#event-modal input[name="event-end-date"]').datepicker('update', event ? event.endDate : '');
$('#event-modal').modal();
}
function deleteEvent(event) {
var dataSource = $('#calendar').data('calendar').getDataSource();
for (var i in dataSource) {
if (dataSource[i].id == event.id) {
dataSource.splice(i, 1);
break;
}
}
$('#calendar').data('calendar').setDataSource(dataSource);
}
function saveEvent() {
var event = {
id: $('#event-modal input[name="event-index"]').val(),
name: $('#event-modal input[name="event-name"]').val(),
location: $('#event-modal input[name="event-location"]').val(),
startDate: $('#event-modal input[name="event-start-date"]').datepicker('getDate'),
endDate: $('#event-modal input[name="event-end-date"]').datepicker('getDate')
}
var dataSource = $('#calendar').data('calendar').getDataSource();
if (event.id) {
for (var i in dataSource) {
if (dataSource[i].id == event.id) {
dataSource[i].name = event.name;
dataSource[i].location = event.location;
dataSource[i].startDate = event.startDate;
dataSource[i].endDate = event.endDate;
}
}
} else {
var newId = 0;
for (var i in dataSource) {
if (dataSource[i].id > newId) {
newId = dataSource[i].id;
}
}
newId++;
event.id = newId;
dataSource.push(event);
}
$('#calendar').data('calendar').setDataSource(dataSource);
$('#event-modal').modal('hide');
}
$(function() {
var currentYear = new Date().getFullYear();
$('#calendar').calendar({
enableContextMenu: true,
enableRangeSelection: true,
contextMenuItems: [{
text: 'Update',
click: editEvent
},
{
text: 'Delete',
click: deleteEvent
}
],
selectRange: function(e) {
editEvent({ startDate: e.startDate, endDate: e.endDate });
},
mouseOnDay: function(e) {
if (e.events.length > 0) {
var content = '';
for (var i in e.events) {
content += '<div class="event-tooltip-content">' +
'<div class="event-name" style="color:' + e.events[i].color + '">' + e.events[i].name + '</div>' +
'<div class="event-location">' + e.events[i].location + '</div>' +
'</div>';
}
$(e.element).popover({
trigger: 'manual',
container: 'body',
html: true,
content: content
});
$(e.element).popover('show');
}
},
mouseOutDay: function(e) {
if (e.events.length > 0) {
$(e.element).popover('hide');
}
},
dayContextMenu: function(e) {
$(e.element).popover('hide');
},
dataSource: [{
id: 0,
name: 'Google I/O',
location: 'San Francisco, CA',
startDate: new Date(currentYear, 4, 28),
endDate: new Date(currentYear, 4, 29)
},
{
id: 1,
name: 'Microsoft Convergence',
location: 'New Orleans, LA',
startDate: new Date(currentYear, 2, 16),
endDate: new Date(currentYear, 2, 19)
},
{
id: 2,
name: 'Microsoft Build Developer Conference',
location: 'San Francisco, CA',
startDate: new Date(currentYear, 3, 29),
endDate: new Date(currentYear, 4, 1)
},
{
id: 3,
name: 'Apple Special Event',
location: 'San Francisco, CA',
startDate: new Date(currentYear, 8, 1),
endDate: new Date(currentYear, 8, 1)
},
{
id: 4,
name: 'Apple Keynote',
location: 'San Francisco, CA',
startDate: new Date(currentYear, 8, 9),
endDate: new Date(currentYear, 8, 9)
},
{
id: 5,
name: 'Chrome Developer Summit',
location: 'Mountain View, CA',
startDate: new Date(currentYear, 10, 17),
endDate: new Date(currentYear, 10, 18)
},
{
id: 6,
name: 'F8 2015',
location: 'San Francisco, CA',
startDate: new Date(currentYear, 2, 25),
endDate: new Date(currentYear, 2, 26)
},
{
id: 7,
name: 'Yahoo Mobile Developer Conference',
location: 'New York',
startDate: new Date(currentYear, 7, 25),
endDate: new Date(currentYear, 7, 26)
},
{
id: 8,
name: 'Android Developer Conference',
location: 'Santa Clara, CA',
startDate: new Date(currentYear, 11, 1),
endDate: new Date(currentYear, 11, 4)
},
{
id: 9,
name: 'LA Tech Summit',
location: 'Los Angeles, CA',
startDate: new Date(currentYear, 10, 17),
endDate: new Date(currentYear, 10, 17)
}
]
});
$('#save-event').click(function() {
saveEvent();
});
});
我不确定这是否是暴露问题的最佳方法,因此,如果您对如何执行此操作有任何意见,最好在评论中随意说。
谢谢。
答案 0 :(得分:0)
对于水平问题,可以将一些CSS
导入到此项目中,并使其变为水平形状,而不是垂直形状。
我建议您使用flexbox
技术:
.wrapper-class {
display: flex;
flex-direction: row;
}
还有更多CSS
以获得更好的视图,这取决于您。但是关于您的JavaScript
错误。我看到了它们,它们不是图书馆而是您的错。寻找并找出错误之处。
例如:
TypeError: null is not an object (evaluating 't.length')
这意味着您编写的东西没有length属性。
我建议您,在Stack Overflow
上提一些大问题,除非有赏金或几次机会,否则永远无法回答。
祝你好运
答案 1 :(得分:0)
将此添加到您的html
<div class="modal fade" id="event-modal">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Event</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<input type="hidden" name="event-index">
<form class="form-horizontal">
<div class="form-group row">
<label for="event-name" class="col-sm-4 control-label">Name</label>
<div class="col-sm-8">
<input id="event-name" name="event-name" type="text" class="form-control">
</div>
</div>
<div class="form-group row">
<label for="event-location" class="col-sm-4 control-label">Location</label>
<div class="col-sm-8">
<input id="event-location" name="event-location" type="text" class="form-control">
</div>
</div>
<div class="form-group row">
<label for="min-date" class="col-sm-4 control-label">Dates</label>
<div class="col-sm-8">
<div class="input-group input-daterange" data-provide="datepicker">
<input id="min-date" name="event-start-date" type="text" class="form-control">
<div class="input-group-prepend input-group-append">
<div class="input-group-text">to</div>
</div>
<input name="event-end-date" type="text" class="form-control">
</div>
</div>
</div>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
<button type="button" class="btn btn-primary" id="save-event">
Save
</button>
</div>
</div>
</div>
</div>
<div id="context-menu">
</div>
然后在页面中包含引导程序。您可以在这里getbootstrap.com
获得更多信息别忘了按照引导页面上的说明放置jQuery和popper.js
将此添加到您的CSS
.calendar table.month td.day .day-content {
padding: 6px;
border-radius: 100%;
}
.calendar .months-container .month-container.month-3{
width:21%;
}
尝试填充和宽度,直到适合为止