Loading [MathJax]/jax/output/CommonHTML/config.js
前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >专栏 >Datepicker日期选择器插件

Datepicker日期选择器插件

作者头像
从入门到进错门
发布于 2018-08-21 08:39:31
发布于 2018-08-21 08:39:31
4K02
代码可运行
举报
运行总次数:2
代码可运行

Datepicker日期选择器插件

这个插件还是比较简单的,而且样式也比较漂亮,可以自定义选择年月日、年月日时分、年月、时间段选择等等。

效果预览:

这个插件是基于jQuery和bootstrap的。因此我们需要引入的文件有:
  1. bootstrap.min.cssbootstrap.css
  2. bootstrap-datepicker.min.cssbootstrap-datepicker.min.css
  3. jquery.min.jsjquery.js
  4. bootstrap-datepicker.min.jsbootstrap-datepicker.js
  5. bootstrap-datepicker.zh-CN.js

其中第五个表示将插件换成中文显示

具体使用方法见代码:

html:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
<div class="container">
    <h1 class="text-center text-info">Datepicker日期选择器插件</h1>
    <!-- 年月日 -->
    <div class="form-group has-success">
        <label class="control-label" for="ymd">年月日
        <div class="input-group">
            <span class="input-group-addon glyphicon glyphicon-time"></span>
            <input type="text" class="form-control" id="ymd" aria-describedby="inputGroupSuccess1Status">
        </div>
    </label>
    </div>

    <!-- 年月日时分 -->
    <div class="form-group has-warning">
        <label class="control-label" for="ymdhm">年月日时分
        <div class="input-group">
            <span class="input-group-addon glyphicon glyphicon-time"></span>
            <input type="text" class="form-control" id="ymdhm" aria-describedby="inputGroupSuccess1Status">
        </div>
    </label>
    </div>
    <table class="table">
        <thead>
            <tr>
                <th>
                    <div class="form-group has-error">
                        <label class="control-label" for="start">开始时间
                        <div class="input-group">
                            <span class="input-group-addon glyphicon glyphicon-time"></span>
                            <input type="text" class="form-control" id="start">
                        </div>
                    </label>
                    </div>
                </th>
                <th>
                    <div class="form-group has-error">
                        <label class="control-label" for="end">结束时间
                        <div class="input-group">
                            <span class="input-group-addon glyphicon glyphicon-time"></span>
                            <input type="text" class="form-control" id="end">
                        </div>
                    </label>
                    </div>
                </th>
            </tr>
        </thead>
    </table>
</div>

js:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
<script>
        $('#ymd').fdatepicker({
            format: 'yyyy-mm-dd',
            language: "zh-CN"
        });
        $('#ymdhm').fdatepicker({
            language: "zh-CN",
            format: 'yyyy-mm-dd hh:ii',
            pickTime: true
        });


        var nowTemp = new Date(0, 0, 0, 0, 0, 0);
        var now = new Date(nowTemp.getFullYear(), nowTemp.getMonth(), nowTemp.getDate(), 0, 0, 0, 0);
        var checkin = $('#start').fdatepicker({
            language: "zh-CN",
            format: 'yyyy-mm-dd',
            onRender: function(date) {
                return date.valueOf() < now.valueOf() ? 'disabled' : '';
            }
        }).on('changeDate', function(ev) {
            if (ev.date.valueOf() > checkout.date.valueOf()) {
                var newDate = new Date(ev.date)
                newDate.setDate(newDate.getDate() + 1);
                checkout.update(newDate);
            }
            checkin.hide();
            $('#end')[0].focus();
        }).data('datepicker');
        var checkout = $('#end').fdatepicker({
            language: "zh-CN",
            format: 'yyyy-mm-dd',
            onRender: function(date) {
                return date.valueOf() <= checkin.date.valueOf() ? 'disabled' : '';
            }
        }).on('changeDate', function(ev) {
            checkout.hide();
        }).data('datepicker');
</script>

github地址:https://github.com/usecodelee/javascript–Datepicker

官方文档:https://bootstrap-datepicker.readthedocs.io/en/stable/

我的博客即将搬运同步至腾讯云+社区,邀请大家一同入驻:https://cloud.tencent.com/developer/support-plan?invite_code=1pk0f70ievu1e

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2018年08月07日,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
暂无评论
推荐阅读
编辑精选文章
换一批
编程世界/前端技术/BootStrap/BootStrap插件组件使用总结
官方地址:https://github.com/smalot/bootstrap-datetimepicker 演示:https://www.bootcss.com/p/bootstrap-datetimepicker/demo.htm
全栈工程师修炼指南
2020/10/23
2.1K0
编程世界/前端技术/BootStrap/BootStrap插件组件使用总结
bootstrap 选择日期和时间
<!doctype html> <html> <head> <meta charset="utf-8"> <title>联想控股</title> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <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">
用户5760343
2019/07/07
3.8K0
前端之路:bootstrap 时间日期日历控件(datetimepicker)
云加速外联即可。(moment-with-locales.js 这个得在datatimpicker.min.js之前。可以网上百度这个文件。我没找到这个cdn)
全栈程序员站长
2022/11/17
7K0
前端之路:bootstrap 时间日期日历控件(datetimepicker)
Bootstrap组件福利篇:几款好用的组件推荐,你值得拥有!
bootstrap风格的时间组件非常多,你可以在github上面随便搜索“datepicker”关键字,可以找到很多的时间组件。博主原来也用过其中的两个,发现都会有一些大大小小的问题。经过一番筛选,找到一个效果不错、能适用各种场景的时间组件,下面就来一睹它的风采吧。
用户1880875
2021/07/27
7920
golang-fullcalendar,engineercms完善日历事件-支持拖曳drop,改变时间resize
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/hotqin888/article/details/54023362
hotqin888
2018/09/11
2K0
golang-fullcalendar,engineercms完善日历事件-支持拖曳drop,改变时间resize
SpringBoot使用Hibernate Validator表单验证
文章目录 一、要求 二、实现步骤 2.1 新建实体类 2.2、创建控制器类UserController 2.3、在templates目录下加入input.html和success.html 2.4、修改application.properties文件 2.5 启动Practice51Application主类,然后访问[http://localhost:8080/practice5_1/](http://localhost:8080/practice5_1/) 2.6输入如下数据,点击添加 一、要求 用户
别团等shy哥发育
2023/02/25
6000
SpringBoot使用Hibernate Validator表单验证
bootstrap-datepicker日期范围
实际应用中可能会根据日期字段查询某个日期范围内的数据,则需要对日期选择器可选时间进行限制,
DencyCheng
2018/11/05
2.4K0
python测试开发django -143.Bootstrap 表单控件校验状态
Bootstrap 对表单控件的校验状态,如 error、warning 和 success 状态,都定义了样式。使用时,添加 .has-warning、.has-error 或 .has-success 类到这些控件的父元素即可。任何包含在此元素之内的 .control-label、.form-control 和 .help-block 元素都将接受这些校验状态的样式。
上海-悠悠
2021/10/08
3480
日期时间选择器、Bootstrap日期和时间表单组件。bootstrap-datetimepicker实现年月日,时分秒的选择。
参考链接:http://www.bootcss.com/p/bootstrap-datetimepicker/
别先生
2019/06/05
4.5K0
日期时间选择器、Bootstrap日期和时间表单组件。bootstrap-datetimepicker实现年月日,时分秒的选择。
Bootstrap实战 - 注册和登录
标签页的使用与导航栏类似,同时都依赖于基础样式 nav,不同的是附加样式变成了 nav-tabs 和 nav-pills(胶囊式),也不用在外面加上一层样式为 navbar navbar-* 的 <div> 元素。
除除
2022/01/13
1.1K0
Bootstrap实战 - 注册和登录
【Bootstrap】006-全局样式:表单
单独的表单控件会被自动赋予一些全局样式。所有设置了 .form-control 类的 <input>、<textarea> 和 <select> 元素都将被默认设置宽度属性为 width: 100%;。 将 label 元素和前面提到的控件包裹在 .form-group 中可以获得最好的排列;
訾博ZiBo
2025/01/06
1060
【Bootstrap】006-全局样式:表单
05.LoT.UI 前后台通用框架分解系列之——漂亮的时间选择器
LOT.UI分解系列汇总:http://www.cnblogs.com/dunitian/p/4822808.html#lotui LoT.UI开源地址如下:https://github.com/du
逸鹏
2018/04/10
6800
05.LoT.UI 前后台通用框架分解系列之——漂亮的时间选择器
Bootstrap响应式前端框架笔记九——输入框组
    将input标签与input-group-addon类组合使用可以为输入框添加前后挂件,需要注意,Bootstrap不支持在输入框控件一侧添加多个挂件,示例如下:
珲少
2018/08/15
1.1K0
Bootstrap响应式前端框架笔记九——输入框组
BootStrap应用开发学习入门
[TOC] 0x00 前言简介 什么是BootStrap? 答:Bootstrap是Twitter 的 Mark Otto 和 Jacob Thornton 开发的推出的一个用于前端开发的开源工具包产
全栈工程师修炼指南
2020/10/23
17.9K0
BootStrap应用开发学习入门
03_Bootstrap基础组件03
设置了 .form-control 类的表单元素,默认设置宽度属性为 width: 100%;。将 label 元素和表单元素包裹在 .form-group 中可以按照排好的样式进行展示。
张哥编程
2024/12/13
520
Bootstrap 时间控件 datetimepicker
Bootstrap 的时间控件易用且美观,下面将用法记录一下,大家有需要可以直接看官网的介绍,还是很基础的。 网址:http://www.bootcss.com/p/bootstrap-datetimepicker/
全栈程序员站长
2022/08/25
4.5K0
Bootstrap 时间控件 datetimepicker
【Bootstrap】012-组件:按钮组、按钮式下拉菜单、输入框组
通过按钮组容器把一组按钮放在同一行里。通过与按钮插件联合使用,可以设置为单选框或多选框的样式和行为;
訾博ZiBo
2025/01/06
1890
【Bootstrap】012-组件:按钮组、按钮式下拉菜单、输入框组
python测试开发django-166.jQuery 使用append()动态添加div元素
在页面上动态添加div元素,比如用户在添加多个银行卡的时候,可以动态添加和删除div元素
上海-悠悠
2021/11/16
2.2K0
Bootstrap【第三章】全局CSS之表单&按钮&图片&辅助类&响应式工具)
class=”form-control”:可以给<input>、<textarea>、<select>元素设置宽度为100%
用户10196776
2022/11/22
1.3K0
Web开发---单页面应用(签到日报--技术实现)
疫情前期,员工分布在各个地区,需要上报个人的健康状态和位置信息,于是做了一个单页面应用(当时钉钉和微信上的健康上报模板还没出现)
MiaoGIS
2020/03/16
8350
Web开发---单页面应用(签到日报--技术实现)
推荐阅读
相关推荐
编程世界/前端技术/BootStrap/BootStrap插件组件使用总结
更多 >
领券
💥开发者 MCP广场重磅上线!
精选全网热门MCP server,让你的AI更好用 🚀
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档
本文部分代码块支持一键运行,欢迎体验
本文部分代码块支持一键运行,欢迎体验