日期组件--仿

参考自:https://github.com/ALiuNa/YTD

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <script src=‘../node_modules/jquery/dist/jquery.min.js‘></script>
</head>
<body>
    <div class="from-group ">
        <select class=‘public_year‘   data-date=‘{year:1920,month:5,date:1,maxAfter:2020,minBefore:1900,year_text:"年",month_text:"月",date_text:"日"}‘    name="" id=""></select>
        <select class=‘public_month‘  name="" id=""></select>
        <select class=‘public_date‘   name="" id=""></select>
    </div>
    <div class="from-group ">
        <select class=‘public_year‘  data-date=‘{year:1932,month:5,date:1,maxAfter:2080,minBefore:1930,year_text:"xxx年",month_text:"xxx月",date_text:"xxx日"}‘  name="" id=""></select>
        <select class=‘public_month‘  name="" id=""></select>
        <select class=‘public_date‘   name="" id=""></select>
    </div>
    <div class="from-group ">
        <select class=‘public_year‘ data-date=‘{year:1901,month:5,date:1,maxAfter:2080,minBefore:1900,year_text:"xxx年",month_text:"xxx月",date_text:"xxx日"}‘   name="" id=""></select>
        <select class=‘public_month‘  name="" id=""></select>
        <select class=‘public_date‘   name="" id=""></select>
    </div>

    <button id=‘aaa‘>11111</button>
</body>
<script src=‘index.js‘></script>

<script>
       $(‘#aaa‘).on(‘click‘,function(){
           var html=‘<div class="from-group ">        <select class="public_year"    name="" id=""></select>        <select class="public_month"  name="" id=""></select>        <select class="public_date"   name="" id=""></select>    </div>‘;
    $(‘body‘).append(html);
           $.selectDate_zd_ready();
       })
</script>
</html>
(function($) {
    $.fn.selectDate_zd = function(call) {
            // $.fn.selectDate_zd
            /*参数规则说明
          $domYear为默认的年组件select
          $domMonth为默认的月组件select
          $domDate 为默认的日组件select
          year 设置默认年,可为空
          month 设置默认月,可为空
          date 设置默认日,可为空
          maxAfter 最多到今年后的哪一年+
          minBefore 最多到哪一年-
          nowYear,nowMonth,nowDate分别代表当前年月日
          year_text,month_text,date_text代表默認的年月日第一天默認值
          例子:
          <select class=‘public_year‘   data-date=‘{year:1920,month:5,date:1,maxAfter:2020,minBefore:1900,year_text:"年",month_text:"月",date_text:"日"}‘    name="" id=""></select>
          <select class=‘public_month‘  name="" id=""></select>
          <select class=‘public_date‘   name="" id=""></select>
          插件信息:
          author:jl,
          參考自:https://github.com/ALiuNa/YTD
           /---------注意--------------/
           在外围后生成的元素需要更启用下
           代码为:
           $.selectDate_zd_ready();
           例:
           $(‘#aaa‘).on(‘click‘,function(){
               var html=‘<div><select class=‘public_year‘></select></div>‘;
               $(body).append(html);
               //启用
               $.selectDate_zd_ready();
           })

        */
            //默认参数  

            var $domYear = $(‘.‘ + call).find(‘.public_year‘),
                $domMonth = $(‘.‘ + call).find(‘.public_month‘),
                $domDate = $(‘.‘ + call).find(‘.public_date‘);
            if (!$domYear.length) return false;
            var defaults = {
                year: 0,
                month: 0,
                date: 0,
                maxAfter: new Date().getFullYear(),
                minBefore: 1948,
                year_text: "-请选择年份-",
                month_text: "-请选择月份-",
                date_text: "-请选择日期-"
            }

            $domYear.each(function(index, el) {
                opts = toObject($(this).data(‘date‘));
            });
            //如果有设置值则引用设置值否则默认
            // var self={};

            this.options = $.extend({}, defaults, opts);
            //声明公用变量名
            var year = this.options.year,
                month = this.options.month,
                date = this.options.date,
                maxAfter = this.options.maxAfter,
                minBefore = this.options.minBefore,
                year_text = this.options.year_text,
                month_text = this.options.month_text,
                date_text = this.options.date_text,
                nowYear = new Date().getFullYear(),
                nowMonth = new Date().getMonth() + 1,
                nowDate = new Date().getDate();
            $domYear.on(‘change‘, set_month);
            $domMonth.on(‘change‘, set_date);
            // 设置年
            function set_year() {
                $domYear.empty();
                $domYear.append("<option value=‘0‘>" + year_text + "</option>");
                for (var i = maxAfter; i > minBefore; i--) {
                    $domYear.append("<option value=‘" + i + "‘>" + i + "年</option>");
                    if (year === i) {
                        $domYear.val(i);
                    }
                }
                if ($domMonth.length) set_month($domYear.val());
            }
            //設置月
            function set_month() {
                $domMonth.empty();
                if ($domYear.val() === 0) { $domMonth.val(0) }
                $domMonth.append("<option value=‘0‘>" + month_text + "</option>");
                if ($domYear.val() > 0) {
                    for (var i = 1; i < 13; i++) {
                        $domMonth.append("<option value=‘" + i + "‘>" + i + "月</option>");
                        if (month === i) {
                            $domMonth.val(i);
                        }
                    }
                }
                if ($domDate.length) set_date($domMonth.val());

            }

            //設置日期
            function set_date() {
                $domDate.empty();
                if ($domMonth.val() === 0) { $domDate.val(0) }
                $domDate.append("<option value=‘0‘>" + date_text + "</option>");
                if ($domYear.val() > 0 && $domMonth.val() > 0) {
                    //獲取設置年月的時間,月份比當前月份少一,1代表月第一天,0就可以獲取上個月的最後一天
                    var settingData = new Date($domYear.val(), $domMonth.val(), 0),
                        settingDate = settingData.getDate();
                    for (var i = 1; i <= parseInt(settingDate); i++) {
                        $domDate.append("<option value=‘" + i + "‘>" + i + "日</option>");
                        if (date === i) {
                            $domDate.val(i);
                        }
                    }
                }

            }
            //公用方法:将字符串转化为object对象
            function toObject(a) {
                return (new Function(‘return ‘ + a))();
            };
            set_year();
        }
        //作用域问题,生成父级class用来区分,所以一组select必须用一个父级包起来
    jQuery.selectDate_zd_ready = function() {
        $(‘.public_year‘).each(function(i, e) {
            $(this).parent().addClass(‘selectRandom_‘ + i);
            $(document).selectDate_zd(‘selectRandom_‘ + i)
        })
    }
    $.selectDate_zd_ready();
}(jQuery));
时间: 2025-01-03 20:51:07

日期组件--仿的相关文章

日期组件wdatepicker

导入WdataPicker文件包到项目的js文件夹下: 在用户管理中的添加.编辑jsp页面对生日表单项引入日期组件: <script type="text/javascript" src="${basePath }js/datepicker/WdatePicker.js"></script> 用法: 1 <s:textfield id="birthday" name="user.birthday"

vue自定义日期组件

vue-datepicker 基于 vuejs 2.x 可自定义主题的日期组件 github Usage 只需要在项目中加入 calendar.vue,就可以使用了. 向组件传入 prop 即可改变 calendar 的样式 Props type(String): 默认 single(选择单天),可选 range(选择多天) / time(选择单天 + 时间) isAbandon(Boolean): 默认 true,早于系统日期的日期选项是否不可选 showInput(Boolean): 默认

EXTJS项目实战经验总结一:日期组件的change事件:

1  依据选择的日期,加载相应的列表数据,如图:   开发说明    1 开发思路: 在日期值变化的事件中获得选择后的日期值,传给后台,然后从后台加载相应的数据 2 问题:在查看extjs2.2 的api的官方说明文档,文档对datefield组件的change事件说明如下: change : ( Ext.form.Field this, Mixed newValue, Mixed oldValue )       Fires just before the field blurs if the

JavaScript日期组件的实现

旅游频道的开发中需要定义各种日期组件,有的是基本的日期选择, 这个基本日期只包含如下功能 左右翻(月) 点击天回填到输入域 点击"今天",回填今天的日期到输入域 点击"关闭",日期控件关闭 有的同时显示两个月的日期 有的包含一些业务信息,比如机票搜索结果页的低价日历. 这个比上面的要复杂一些 每天的日期格子里含有价格信息 点击左右箭头会向后退请求更新每天的低价机票信息 且点击每天的格子是会重新查询 这里记录下一个基本日历组件的要点 一.html结构 这里以table

yii2超好用的日期组件和时间组件

作者:白狼 出处:http://www.manks.top/yii2_datetimepicker.html 本文版权归作者,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利.原文有图片.日期组件,时间组件在平时开发中是必不可少的.今天我们就来谈谈在yii2中的超好用的时间组件,也省的大家各种找js插件了. 分享之前我们先预览下效果,看看到底怎么个好用法.当然啦,好用不好用在于自我的感觉,光看上面的图片是感受不到的.再告诉你个好消息,这两款插

【ExtJs】带日期组件的文本输入框、容器与Ext.Msg.alert告警框告警两次

ExtJs的UI组件主要模仿客户端的界面效果,甚至其编程方式都有类似之处. 一.基本目标 比如如下的组件,与VC6中的<[mfc]不同对话框之间互相操控.全局变量与日期控件>(点击打开链接)就有异曲同工之妙. 其基本的思想也是先设置两个日期组件与按钮组件,然后,在点击按钮,就触发事件. 二.制作过程 首先,这个网页全程运用ExtJs编程,因此基本的HTML布局,处理引入ExtJS资源之外什么都没有.甚至可以把下面的ExtJs脚本完全写在一个Js里面. <!DOCTYPE HTML PUB

iview的table组件中加入超链接组件,可编辑组件,选择组件,日期组件

这篇文章主要介绍了iview的table组件中使用选择框,日期,可编辑表格,超链接等组件. 1.select选择组件 // tableColumn数组响应对象需要传入一个固定的option数组,如果该数组是异步动态生成的该组件不能正常渲染,因为在获取option数组之前table渲染时option是undefined. supportSelect(item) { item.render = (h, params)=>{ return h('Select', { props: { value: p

react native中利用Picker自定义日期组件(只包含年和月)

因为业务需求,定义只包含年月的日期,react-native自带组件不符合,第三方鸡肋,于是自己写一个,安卓和IOS样式不同,自己体验调用方法示例: import PickerData from '..//Picker'; <PickerData visible={store.visibleReferee} onCancel={ () => { store.visibleReferee = false; return null; } } onRequestClose={ () => {

element-ui日期组件DatePicker设置日期选择范围Picker Options

element-UI提供了DatePicker日期选择器组件,可以让我们很方便的获取到日期,默认的选择是全部的日期都可以选择的,但是很多场景中我们要对日期选择范围做限定,比如出行日期就不能选过去的日期,订票时间要限制日期范围 官网提供了picker-options参数可以设置日期选择范围,具体操作看代码 // 页面引入组件, 加上picker-options这个参数 <el-date-picker v-model="exCheckDate" type="date&quo