twitter-bootstrap Bootstrap Datepicker 2.0 选择多个日期

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25720867/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 21:29:54  来源:igfitidea点击:

Bootstrap Datepicker 2.0 To select multiple dates

jquerytwitter-bootstrapdatepicker

提问by A.J.

I am using a datepicker from bootstrap 2.0, I want to be able to select multiple dates from the UI.

我正在使用 bootstrap 2.0 中的日期选择器,我希望能够从 UI 中选择多个日期。

Is there any way I can do this?

有什么办法可以做到这一点吗?

<input size="16" type="text" class="form_datetime">

<script type="text/javascript">
    $(".form_datetime").datetimepicker({format: 'yyyy-mm-dd'});
</script>   

采纳答案by A.J.

So easy if you are using bootstrap. Just use multidateto true

如果您使用引导程序,那么简单。只是multidate用来true

Code:

代码:

$('#datepicker').datepicker({
                multidate: true,
            });

Reference Here

参考 这里

good to go.

很高兴去。

回答by Jerome2606

You need to store the selected dates into a variable (static, php or other languages) and use the beforeShowDay to display if the date is selected or not.

您需要将选定的日期存储到一个变量(静态、php 或其他语言)中,并使用 beforeShowDay 来显示是否选择了日期。

beforeShowDay: function (date){
                      for (i = 0; i < calendarEvents.length; i++) {
                          if (date.getMonth() == calendarEvents[i][0] - 1
                          && date.getDate() == calendarEvents[i][1]
                          && date.getFullYear() == calendarEvents[i][2]) {
                          //[disable/enable, class for styling appearance, tool tip]
                          return [false,"ui-state-active","Event Name"];
                          }
                       }
                       return [true, ""];//enable all other days
                    }
       });

where calendarEvents is an array of dates

其中 calendarEvents 是一个日期数组