本文转自:http://yuilibrary.com/yui/docs/calendar/calendar-multipane.html

This example demonstrates how to instantiate a Calendar, switch its template to a double-pane, and create custom renderers for its header and certain cells (based on rules), as well as turn on multiple date selection and disable certain dates from being selected.

The selectionMode in this example is set to multiple, which allows additional dates to be selected if a Shift or Ctrl/Meta key is held down. This selection mode does not allow multiple selection on touchscreen devices; for such devices, use the multiple-sticky selection mode instead.

There are two custom filtering rules provided in the example code. One matches all Saturdays and Sundays (weekends in the United States), and the other matches Tuesdays and Fridays. The first rule is used in conjunction with a custom renderer to set the corresponding date cell text color to red. The second rule is used to disable matching dates from selection and interaction.

<

July 2011 — August 2011

>

Su Mo Tu We Th Fr Sa
25 26 27 28 29 30 1 2 3 4 5 6 7
2 3 4 5 6 7 8 9 10 11 12 13 14
9 10 11 12 13 14 15 16 17 18 19 20 21
16 17 18 19 20 21 22 23 24 25 26 27 28
23 24 25 26 27 28 29 30 31        
30 31                      
Su Mo Tu We Th Fr Sa
            1 2 3 4 5 6 7
2 3 4 5 6 7 8 9 10 11 12 13 14
9 10 11 12 13 14 15 16 17 18 19 20 21
16 17 18 19 20 21 22 23 24 25 26 27 28
23 24 25 26 27 28 29 30 31 1 2 3  
30 31       4 5 6 7 8 9 10  

Complete Example Source

Note: be sure to add the yui3-skin-sam classname to the page's <body> element or to a parent element of the widget in order to apply the default CSS skin. See Understanding Skinning.

<style>.yui3-skin-sam .redtext {color:#ff0000;}</style><divid="demo"class="yui3-skin-sam"><!-- You need this skin class --><divid="mycalendar"></div></div><scripttype="text/javascript">
YUI().use('calendar','datatype-date','datatype-date-math',function(Y){// Switch the calendar main template to the included two pane template
Y.CalendarBase.CONTENT_TEMPLATE = Y.CalendarBase.TWO_PANE_TEMPLATE;// Create a new instance of calendar, setting the showing of previous// and next month's dates to true, and the selection mode to multiple// selected dates. Additionally, set the disabledDatesRule to a name of// the rule which, when matched, will force the date to be excluded// from being selected. Also configure the initial date on the calendar// to be July of 2011.var calendar =new Y.Calendar({
contentBox:"#mycalendar",
width:"700px",
showPrevMonth:true,
showNextMonth:true,
selectionMode:'multiple',
disabledDatesRule:"tuesdays_and_fridays",
date:newDate(2011,6,1)}).render();// Create a set of rules to match specific dates. In this case,// the "tuesdays_and_fridays" rule will match any Tuesday or Friday,// whereas the "all_weekends" rule will match any Saturday or Sunday.var rules ={"all":{"all":{"all":{"2,5":"tuesdays_and_fridays","0,6":"all_weekends"}}}};// Set the calendar customRenderer, provides the rules defined above,// as well as a filter function. The filter function receives a reference// to the node corresponding to the DOM element of the date that matched// one or more rule, along with the list of rules. Check if one of the// rules is "all_weekends", and if so, apply a custom CSS class to the// node.
calendar.set("customRenderer",{
rules: rules,
filterFunction:function(date, node, rules){if(Y.Array.indexOf(rules,'all_weekends')>=0){
node.addClass("redtext");}}});// Set a custom header renderer with a callback function,// which receives the current date and outputs a string.// use the Y.Datatype.Date format to format the date, and// the Datatype.Date math to add one month to the current// date, so both months can appear in the header (since // this is a two-pane calendar).
calendar.set("headerRenderer",function(curDate){var ydate = Y.DataType.Date,
output = ydate.format(curDate,{
format:"%B %Y"})+" &mdash; "+ ydate.format(ydate.addMonths(curDate,1),{
format:"%B %Y"});return output;});// When selection changes, output the fired event to the// console. the newSelection attribute in the event facade// will contain the list of currently selected dates (or be// empty if all dates have been deselected).
calendar.on("selectionChange",function(ev){
Y.log(ev);});});</script>

[引]雅虎日历控件 Example: Two-Pane Calendar with Custom Rendering and Multiple Selection的更多相关文章

  1. JS日历控件优化(增加时分秒)

    JS日历控件优化      在今年7月份时候 写了一篇关于 "JS日历控件" 的文章 , 当时只支持 年月日 的日历控件,现在优化如下:      1. 在原基础上 支持 yyyy ...

  2. JQuery日历控件

    日历控件最后一弹——JQuery实现,换汤不换药.原理一模一样,换了种实现工具.关于日历的终于写完了,接下来研究研究nodejs.嗯,近期就这点事了. 同样还是将input的id设置成calendar ...

  3. javascript日历控件——纯javascript版

    平时只有下班时间能code,闲来写了个纯javascript版.引用该calendar.js文件,然后给要设置成日历控件的input的id设置成calendar,该input就会变成日历控件. < ...

  4. IOS自定义日历控件的简单实现(附思想及过程)

    因为程序要求要插入一个日历控件,该空间的要求是从当天开始及以后的六个月内的日历,上网查资料基本上都说只要获取两个条件(当月第一天周几和本月一共有多少天)就可以实现一个简单的日历,剩下的靠自己的简单逻辑 ...

  5. 【转】【WebDriver】不可编辑域和日历控件域的输入 javascript

    http://blog.csdn.net/fudax/article/details/8089404 今天用到日历控件,用第一个javascript执行后页面上的日期控件后,在html中可以看到生效日 ...

  6. javascript日历控件

    以前要用到日历控件都是直接从网上下载一套源码来使用,心里一直有个梗,就是想自己动手写一个日历控件,最近刚好来了兴趣,时间上也允许,于是自己摸索写了一个,功能还算完善,界面就凑合了.可能最值得说的一点就 ...

  7. 用MVC的辅助方法自定义了两个控件:“可编辑的下拉框控件”和“文本框日历控件”

    接触MVC也没多长时间,一开始学的时候绝得MVC结构比较清晰.后来入了门具体操作下来感觉MVC控件怎么这么少还不可以像ASP.net form那样拖拽.这样设计界面来,想我种以前没学过JS,Jquer ...

  8. Jquery自定义扩展方法(二)--HTML日历控件

    一.概述 研究了上节的Jquery自定义扩展方法,自己一直想做用jquery写一个小的插件,工作中也用到了用JQuery的日历插件,自己琢磨着去造个轮子--HTML5手机网页日历控件,废话不多说,先看 ...

  9. Selenium2+python自动化25-js处理日历控件(修改readonly属性)

    前言 日历控件是web网站上经常会遇到的一个场景,有些输入框是可以直接输入日期的,有些不能,以我们经常抢票的12306网站为例,详细讲解如何解决日历控件为readonly属性的问题. 基本思路:先用j ...

随机推荐

  1. 零点起飞学HTML+CSS (顼宇峰) PDF扫描版

    零点起飞学HTML+CSS系统地介绍了网站制作中各种常用的HTML标签和CSS属性,以及网站各个部分和各种布局的实现方法,还提供了大量实例来引导读者学习,力求让读者获得真正实用的知识.本书涉及面广,从 ...

  2. C#之WinForm界面分辨率问题

    在做上一个C#小工具的时候,当时为了处理界面最大化,分辨率问题,只是简单的用各种···Panle控价简单随意的处理控件的大小位置,字体什么的就随缘了(貌似有点不负责任啊,嘿嘿~). 所以在开始第二个C ...

  3. C# 写 LeetCode easy #14 Longest Common Prefix

    14.Longest Common Prefix Write a function to find the longest common prefix string amongst an array ...

  4. asp.net core 之多语言国际化自定义资源文件

    先说说 asp.net core 默认的多语言和国际化. 官方文档 一:基本使用方法 先要安装 包 Microsoft.AspNetCore.Mvc.Localization (依赖 Microsof ...

  5. Wannafly挑战赛28B(DP,思维,字符串)

    #include<bits/stdc++.h>using namespace std;int n;int nxt[3][100007];char buff[100007];const ch ...

  6. es数据增删改查

    设置最大查询条数 curl -XPUT 'http://10.121.8.5:9200/zdl_mx_shzt_ztdf/_settings' -d'{"index":{" ...

  7. bzoj 3131 [Sdoi2013]淘金(数位dp)

    题目描述 小Z在玩一个叫做<淘金者>的游戏.游戏的世界是一个二维坐标.X轴.Y轴坐标范围均为1..N.初始的时候,所有的整数坐标点上均有一块金子,共N*N块. 一阵风吹过,金子的位置发生了 ...

  8. 关于cuda拷贝的速度测试

    由于没有使用profiler,仅仅通过简单的传输函数测试,如下测试了10000个点,1000000个点,100000000个点的速度: 均按时钟周期来计时,通过MAX调整数据 int main(){ ...

  9. SP16549 QTREE6 - Query on a tree VI LCT维护颜色联通块

    \(\color{#0066ff}{ 题目描述 }\) 给你一棵n个点的树,编号1~n.每个点可以是黑色,可以是白色.初始时所有点都是黑色.下面有两种操作请你操作给我们看: 0 u:询问有多少个节点v ...

  10. luogu3380 树套树之线段树套线段树

    个人感觉可能是最不需要脑子写的方法 不过也不太好调 就是用一个普通的线段树维护这个序列,但是对于线段树的每一个区间,再开一个动态开点的权值线段树,里面存储这个区间所有元素值 单点修改只会涉及到log棵 ...