如何使用Kalendae的getselected功能

时间:2019-02-05 14:25:38

标签: javascript html netbeans

非常新手的问题,我只想知道如何使用getSelected()函数在Kalendae日历中获取所选日期的值。选择这些值后,我需要将它们存储在变量中。

我正在使用多个选择日历,并且试图记录选择的日期,但似乎无法获取值,我试图将其放入var中,但我认为没有正确地做。

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

我希望获得像这样的值:

  • 2/5/2019
  • 2/7/2019
  • 2/9/2019

选择后,但我什至没有任何结果。

1 个答案:

答案 0 :(得分:1)

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

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

希望对您有帮助