javascript - How to use getselected function of Kalendae
问题描述
Very novice problem, I just want to know how I can get the values of the selected dates in a Kalendae calendar using the getSelected() function. I need to store the values in a variable after they are selected.
I'm using multiple select calendar and I'm trying to record the dates selected but can't seem to get the values, I tried to put it in a var but I think I am not doing it correctly.
<html>
<head>
<title>Date Select</title>
<link rel="stylesheet" href="build/kalendae.css" type="text/css" charset="utf-8">
<script src="build/kalendae.standalone.js" type="text/javascript" charset="utf-8">
<style type="text/css" media="screen">
.kalendae .k-days span.closed {
background:red;
}
</style>
</head>
<body onload="getDate()">
<center>
<h4>Pick a date.</h4>
<div id="myDiv" class="auto-kal" data-kal="months:1, mode:'multiple'"></div>
<script>function getDate(){
var k = new Kalendae('myDiv');
k.subscribe('change', function (date) {
console.log(date, this.getSelected());
});
}<script>
</center>
</body>
</html>
I expect to get values like:
- 2/5/2019
- 2/7/2019
- 2/9/2019
After selecting, but I don't even get any result.
解决方案
对我来说,这段代码可以满足您的需求。你有多个问题。我试图在评论中解释它:
<html>
<head>
<title>Date Select</title>
<link rel="stylesheet" href="build/kalendae.css" type="text/css" charset="utf-8">
<script src="build/kalendae.standalone.js" type="text/javascript" charset="utf-8">
</script> //Here you have to add closing script Tag
<style type="text/css" media="screen">
.kalendae .k-days span.closed {
background: red;
}
</style>
</head>
<body>
<center>
<h4>Pick a date.</h4>
<!-- If you use class="auto-kal" the kalendae library generates a new Kalendae
that does not have anything to do with your generated Kalendae object below. So
you have to add a div with the ID myDiv that you are using in new
Kalendae('myDiv'). If you want to understand this you can add "<div class="auto-
kal" data-kal="months:1, mode:'multiple'"> </div> " and you see two calendars
-->
<div id="myDiv" class="myDiv"></div>
<script>
//You doesn't have a Div HTML-Tag with myDiv - Id so
//this Kalendae was never displayed.
//Especially your function getDate() was never called. So this code
//never runs.
var k = new Kalendae('myDiv', {
months:1,
mode:'single',
selected:Kalendae.moment().subtract({M:1})
});
k.subscribe('change', function (date) {
console.log(date, this.getSelected());
});
</script>
</center>
</body>
</html>
我希望这可以帮助你
推荐阅读
- python - 未显示 drf django 的字段
- installshield - 已发布安装程序错误地具有更高版本,例如 1.6 当前安装程序项目具有 1.1 版本 需要将 1.5 升级到 1.1
- microsoft-teams - 无法重新创建已删除的频道
- git - 为什么在 gitlab/git merge-request/merge 期间我得到一个分离的 HEAD?
- vb.net - 在 VB.NET 中使用 datediff 时出现转换错误
- java - Java是前端技术,php是后端技术。我怎么能连接两者?
- rust - 如何从 OsStr 和 str 组件构建 URL?
- android - motionlayout - 转换完成时视图隐藏
- kubernetes - 在 Kubernetes 中检索服务的全名
- asp.net - 域模型类拆分为单独的程序集