首页 > 解决方案 > 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:

After selecting, but I don't even get any result.

标签: javascripthtmlnetbeans

解决方案


对我来说,这段代码可以满足您的需求。你有多个问题。我试图在评论中解释它:

<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>

我希望这可以帮助你


推荐阅读