本文转自: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. Mysql--连接查询

    内连接查询 意义:找到表和表之间的关系或者是桥梁.连接查询是查询两个或者两个以上的表时使用的. JOIN|CROSS JOIN| INNER JOIN    通过ON  连接条件(这三个方式都行)一般 ...

  2. 如何破解IDEA

    https://blog.csdn.net/samery1020/article/details/79489164 http://idea.lanyus.com/ 我们在选择JAVA 使用IDEA时都 ...

  3. 大白话解说TCP/IP协议三次握手和四次挥手

    背景 和女朋友异地恋一年多,为了保持感情我提议每天晚上视频聊天一次. 从好上开始,到现在,一年多也算坚持下来了. 问题 有时候聊天的过程中,我的网络或者她的网络可能会不好,视频就会卡住,听不到对方的声 ...

  4. CF70D(动态凸包)

    CF70D(动态凸包) 给出q(<=1e5)个询问,每次在加上一个点,维护凸包,或者询问某个点是否在凸包内(在边上也算). 听说可以用cdq做--但是并不会.我等蒟蒻只会用平衡树做. 首先,假设 ...

  5. P1472 奶牛家谱 Cow Pedigrees

    题意:问你指定二叉树有几种 1.高度为k 2.节点数为n 3.每个点的度为0或2 爆搜------->30分QAQ 首先,因为每个节点度为0或2, 所以如果n是偶数直接输出0就行了吧(嘿嘿) 如 ...

  6. 快速找出故障机器(single number)

    简单起见,假设每个机器存储一个标号为ID的记录(ID是小于十亿的整数),假设每份数据都保存两个备份,这样就有两个机器储存了同样的数据. 1.在某个时间,如果得到一个数据文件ID的列表,是否能够快速地找 ...

  7. StackOverflow

    stackoverflow栈溢出 stacker栈式存储器 signup注册  signin登陆 inbox收信信箱 verify 核实 otherwise另外的 noted说明  (就是说有明文指出 ...

  8. 设置linux服务器文件夹权限

    最近搞的网站一上传图片,就报500错误.经排查是服务器文件夹权限设置问题. 使用命令: chmod o+rwx avatar 即可改变文件夹权限设置.

  9. Mybatis学习笔记(九) —— Mybatis逆向工程

    一.什么是Mybatis逆向工程? 简单的解释就是通过数据库中的单表,自动生成java代码. 我们平时在使用Mabatis框架进行Web应用开发的过程中,需要根据数据库表编写对应的Pojo类和Mapp ...

  10. Linux不同发型版本(Debian REHL)与软件包管理器(RPM dpkg)的概念

    Linux的发行版本可以大体分为两类: Linux发行版 = Linux内核(类Unix内核) + Linux软件管理(package manager) 一类是商业公司维护的发行版本,以著名的Red ...