Does bootstrap have a calendar control?

藏色散人
Release: 2023-02-10 14:34:52
Original
4661 people have browsed it

bootstrap has a calendar control, a time and date calendar control, named "datetimepicker". It is a Bootstrap component that can simplify the input of date and time on the page. The datetimepicker control supports date selection and format setting, and supports time period selection control. You only need to use script and link tags to introduce relevant files on the required page to use it.

Does bootstrap have a calendar control?

#The operating environment of this article: Windows7 system, bootstrap3, Dell G3 computer.

Does bootstrap have a calendar control?

bootstrap has a time and date calendar control, named datetimepicker, which is a Bootstrap component that can simplify the input of date and time on the page.

Usage of Bootstrap datetimepicker control

1. Support date selection and format setting

2. Support time selection

3. Support time period selection control

4. Support Chinese

Involved styles and js:

<link href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
<link href="https://cdn.bootcss.com/bootstrap-datetimepicker/4.17.47/css/bootstrap-datetimepicker.min.css" rel="stylesheet">
 
<script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.js"></script>
<script src="https://cdn.bootcss.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script src="static/js/moment-with-locales.js"></script>
<script src="https://cdn.bootcss.com/bootstrap-datetimepicker/4.17.47/js/bootstrap-datetimepicker.min.js"></script>
Copy after login

Let’s go directly to the example.

<div class="row">
    <div class=&#39;col-sm-6&#39;>
        <div class="form-group">
            <label>选择日期:</label>
            <!--指定 date标记-->
            <div class=&#39;input-group date&#39; id=&#39;datetimepicker1&#39;>
                <input type=&#39;text&#39; class="form-control" />
                <span class="input-group-addon">
                    <span class="glyphicon glyphicon-calendar"></span>
                </span>
            </div>
        </div>
    </div>
    <div class=&#39;col-sm-6&#39;>
        <div class="form-group">
            <label>选择日期+时间:</label>
            <!--指定 date标记-->
            <div class=&#39;input-group date&#39; id=&#39;datetimepicker2&#39;>
                <input type=&#39;text&#39; class="form-control" />
                <span class="input-group-addon">
                    <span class="glyphicon glyphicon-calendar"></span>
                </span>
            </div>
        </div>
    </div>
</div>
$(function () {
    $(&#39;#datetimepicker1&#39;).datetimepicker({
        format: &#39;YYYY-MM-DD&#39;,
        locale: moment.locale(&#39;zh-cn&#39;)
    });
    $(&#39;#datetimepicker2&#39;).datetimepicker({
        format: &#39;YYYY-MM-DD hh:mm&#39;,
        locale: moment.locale(&#39;zh-cn&#39;)
    });
});
 
 
 
/*4.17版本一些可能用得到的方法参数*/
/*
        showClose:true//是否显示关闭 按钮
        /*viewMode: &#39;days&#39;,//天数模块展示,months则为以月展示
        daysOfWeekDisabled: false,//星期几 禁止选择,参数 [num],多个逗号隔开
        calendarWeeks: false,//显示 周 是 今年第几周
        toolbarPlacement:&#39;default&#39;, //工具摆放的位置,top 则为上,默认为底
        showTodayButton:false,//是否工具栏 显示 直达今天天数的 按钮,默认false
        showClear:false, //是否 工具栏显示  清空 输入框  的按钮。默认false
*/
Copy after login

Screenshot:

Does bootstrap have a calendar control?

## Example of starting time:

<div class="row">
    <div class=&#39;col-sm-6&#39;>
        <div class="form-group">
            <label>选择开始时间:</label>
            <!--指定 date标记-->
            <div class=&#39;input-group date&#39; id=&#39;datetimepicker1&#39;>
                <input type=&#39;text&#39; class="form-control" />
                <span class="input-group-addon">
                    <span class="glyphicon glyphicon-calendar"></span>
                </span>
            </div>
        </div>
    </div>
    <div class=&#39;col-sm-6&#39;>
        <div class="form-group">
            <label>选择结束时间:</label>
            <!--指定 date标记-->
            <div class=&#39;input-group date&#39; id=&#39;datetimepicker2&#39;>
                <input type=&#39;text&#39; class="form-control" />
                <span class="input-group-addon">
                    <span class="glyphicon glyphicon-calendar"></span>
                </span>
            </div>
        </div>
    </div>
</div>
$(function () {
    var picker1 = $(&#39;#datetimepicker1&#39;).datetimepicker({
        format: &#39;YYYY-MM-DD&#39;,
        locale: moment.locale(&#39;zh-cn&#39;),
        //minDate: &#39;2016-7-1&#39;
    });
    var picker2 = $(&#39;#datetimepicker2&#39;).datetimepicker({
        format: &#39;YYYY-MM-DD&#39;,
        locale: moment.locale(&#39;zh-cn&#39;)
    });
    //动态设置最小值
    picker1.on(&#39;dp.change&#39;, function (e) {
        picker2.data(&#39;DateTimePicker&#39;).minDate(e.date);
    });
    //动态设置最大值
    picker2.on(&#39;dp.change&#39;, function (e) {
        picker1.data(&#39;DateTimePicker&#39;).maxDate(e.date);
    });
});
Copy after login

Screenshot:

Does bootstrap have a calendar control?

During initialization, use defaultDate to specify the default time:

 $(&#39;#datetimepicker1&#39;).datetimepicker({
            format: &#39;YYYY-MM-DD&#39;,
            locale: moment.locale(&#39;zh-cn&#39;),
            defaultDate: "1990-1-1"
        });
Copy after login

Of course, you can also use JS code to control the default value of the input box.

Specific example:

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width" />
<title>datetimpicker测试</title>
<!--图标样式-->
<link href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
<link href="https://cdn.bootcss.com/bootstrap-datetimepicker/4.17.47/css/bootstrap-datetimepicker.min.css" rel="stylesheet">
<script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.js"></script>
<script src="https://cdn.bootcss.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script src="https://cdn.bootcss.com/moment.js/2.24.0/moment-with-locales.js"></script>
<script src="https://cdn.bootcss.com/bootstrap-datetimepicker/4.17.47/js/bootstrap-datetimepicker.min.js"></script>
</head>
<body>
<div class="container">
<div class="row">
<div class=&#39;col-sm-6&#39;>
<div class="form-group">
<label>选择日期:</label>
<!--指定 date标记-->
<div class=&#39;input-group date&#39; id=&#39;datetimepicker1&#39;>
<input type=&#39;text&#39; class="form-control" />
<span class="input-group-addon">
                    <span class="glyphicon glyphicon-calendar"></span>
</span>
</div>
</div>
</div>
<div class=&#39;col-sm-6&#39;>
<div class="form-group">
<label>选择日期+时间:</label>
<!--指定 date标记-->
<div class=&#39;input-group date&#39; id=&#39;datetimepicker2&#39;>
<input type=&#39;text&#39; class="form-control" />
<span class="input-group-addon">
                    <span class="glyphicon glyphicon-calendar"></span>
</span>
</div>
</div>
</div>
</div>
</div>
<script type="text/javascript">
$(function() {
$(&#39;#datetimepicker1&#39;).datetimepicker({
format: &#39;YYYY-MM-DD&#39;,
locale: moment.locale(&#39;zh-cn&#39;)
});
$(&#39;#datetimepicker2&#39;).datetimepicker({
format: &#39;YYYY-MM-DD hh:mm&#39;,
locale: moment.locale(&#39;zh-cn&#39;)
});
});
</script>
    </body>
</html>
Copy after login

Does bootstrap have a calendar control?

Recommended: "

bootstrap tutorial"

The above is the detailed content of Does bootstrap have a calendar control?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template