第二百一十四节,jQuery EasyUI,Calendar(日历)组件

jQuery EasyUI,Calendar(日历)组件

 

学习要点:

  1.加载方式

  2.属性列表

  3.事件列表

  4.方法列表

 

本节课重点了解 EasyUI 中 Canlendar(日历)组件的使用方法,这个组件不依赖于其 他组件。

 

一.加载方式

class 加载方式

<div id="box" class="easyui-calendar" style="width:200px;height:200px;"></div>

calendar()将一个元素执行日历组件

 

JS 加载调用

$(function () {
    $('#box').calendar({

    });
});

 

 

二.属性列表

 

width   number 日历控件宽度。默认值180。

$(function () {
    $('#box').calendar({
        width:400,
        height:300
    });
});

 

height   number 日历控件高度。默认值180。

$(function () {
    $('#box').calendar({
        width:400,
        height:300
    });
});

 

fit   boolean 当设置为 true 的时候,将设置日历控件大小自适应父容器。默认值 false。

$(function () {
    $('#box').calendar({
        width:400,
        height:300,
        fit:true        //当设置为 true 的时候,将设置日历控件大小自适应父容器。默认值 false。
    });
});

 

border   boolean 定义是否显示边框。默认值 true。

$(function () {
    $('#box').calendar({
        width:400,
        height:300,
        border:false    //定义是否显示边框。默认值 true。
    });
});

 

firstDay   number 定义一周的第一天是星期几。0=星期日、1=星期一 等。定义星期几的排序0从星期日排序1从星期一排序

$(function () {
    $('#box').calendar({
        width:400,
        height:300,
        firstDay:1  //定义星期几的排序0从星期日排序1从星期一排序
    });
});

 

weeks   array显 示 的 周 列 表 内 容 。 默 认 值 :['S','M','T','W','T','F','S'],定义星期几的显示文字

$(function () {
    $('#box').calendar({
        width:400,
        height:300,
        weeks:['S','M','T','W','T','F','S']  //定义星期几的显示文字
    });
});

 

months   array显示的月列表内容。默认值:['Jan','Feb', 'Mar', 'Apr', 'May','Jun', 'Jul', 'Aug','Sep', 'Oct', 'Nov', 'Dec'],定义月份显示文字

$(function () {
    $('#box').calendar({
        width:400,
        height:300,
        months:['Jan','Feb', 'Mar', 'Apr', 'May','Jun', 'Jul', 'Aug','Sep', 'Oct', 'Nov', 'Dec']
    });
});

 

year   number 年日历。下面的例子显示了如何使用指定的年份和月份创建一个日历。设置默认年份

$(function () {
    $('#box').calendar({
        width:400,
        height:300,
        year:1984,      //设置默认年份
        month:9,        //设置默认月份
    });
});

 

month   number 月日历。设置默认月份

$(function () {
    $('#box').calendar({
        width:400,
        height:300,
        year:1984,      //设置默认年份
        month:9,        //设置默认月份
    });
});

 

current   date 当前日期,设置默认当前日期

$(function () {
    $('#box').calendar({
        width:400,
        height:300,
        year:1984,      //设置默认年份
        month:9,        //设置默认月份
        current:new Date(1984,8,25)  //设置默认当前日期,月份从0开始所以9月就写8月
    });
});

 

formatter   date 格式化日期,就是可以给每个日期添加自定义字符

$(function () {
    $('#box').calendar({
        width:400,
        height:300,
        formatter:function (date) {
            return '#' + date.getDate();
        }
    });
});

 

styler   date 设置指定日期的样式,设置日期的样式

$(function () {
    $('#box').calendar({
        width: 400,
        height: 300,
        styler: function (date) {
            if (date.getDate() == 1) {  //将每月1日改变样式
                return 'background-color:#ccc';
            }
        }
    });
});

 

validator   date 设置指定日期是否可以选择

$(function () {
    $('#box').calendar({
        width: 400,
        height: 300,
        validator: function (date) {
            if (date.getDay() == 1) {  //将每个星期一设置为不可用
                return false
            }else {
                return true
            }
        }
    });
});

 

 

三.事件列表

onSelect   date 在用户选择一天的时候触发

$(function () {
    $('#box').calendar({
        width: 400,
        height: 300,
        onSelect: function (date) {
            alert(date.getFullYear() + "-" + (date.getMonth() + 1) + "-" + date.getDate());
            // date.getFullYear()用户选择的年
            // date.getMonth()用户选择的月
            // date.getDate()用户选择的日
        }
    });
});

 


onChange   newDate, oldDate 在用户改变选择的时候触发

 

$(function () {
    $('#box').calendar({
        width: 400,
        height: 300,
        onChange: function (newDate, oldDate) {
            alert(newDate + '|' + oldDate);
            // newDate改变后的日期
            // oldDate改变前的日期
        }
    });
});

 

 

 

四.方法列表

options   none 返回参数对象。

$(function () {
    $('#box').calendar({
        width: 400,
        height: 300,
    });
    alert($('#box').calendar('options'));  //返回参数对象
});

 

resize   none 调整日历大小。就是如果日历变形后重置

$(function () {
    $('#box').calendar({
        width: 400,
        height: 300,
    });
    $('#box').calendar('resize');  //调整日历大小。
});

 

moveTo   date 移动日历到指定日期。默认选择日期

$(function () {
    $('#box').calendar({
        width: 400,
        height: 300,
    });
    $('#box').calendar('moveTo',new Date(2015,1,1));  //移动日历到指定日期
});

 

我们可以使用$.fn.calendar.defaults 重写默认值对象。

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
之前在网上想找一个简单易用的周日历选择插件,发现这种前端周日历插件很少,而且很多文章写的周的算法都不是统一的,所以自己实现了一个基于jquery的周日历插件(还支持跳转到指定年份和周哦)。 插件中周的算法:每周以周日为起始,第一周以每年第一个星期四所在的周为第一周(网上找的好像这个算法比较正规) 实现的效果是在手机端,也可以在PC端用,毕竟功能才是主要的。如果觉得样式不入眼可以自行随意修改。 //调用周日历方法 var weekfn = new jcalendar_week({ element: "#jcalendar_week",//填充日历的dom元素 dayaddclass:function(date){ //添加某天时给添加类名(参数:1.日期)(返回类名字符串,多个以空格分开) return ""; }, dayclick:function(date,obj){ //day点击事件(参数:1.日期,2.所点击DOM元素) $(obj).addClass("calendar_day_act").siblings().removeClass("calendar_day_act"); } }); 点击上方显示当前年份和周的DOM部分可选择并跳转到指定年份和周。 插件提供的方法: //获取周第一天方法weekfirstdate(),传入年份和周数 console.log(weekfn.weekfirstdate(2018,36)); //获取传入日期为当年第几周getweeknum(),传入年,月,日(注:这里的月份从0开始) console.log(weekfn.getweeknum(2018,0,16)); //跳转到指定周confirmweek(),传入年份和周数 weekfn.confirmweek(getyear,getweek); //跳转到本周nowweek() weekfn.nowweek();
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值