[引]雅虎日历控件 Example: Two-Pane Calendar with Custom Rendering and Multiple Selection
本文转自: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.
| 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"})+" — "+ 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的更多相关文章
- JS日历控件优化(增加时分秒)
		
JS日历控件优化 在今年7月份时候 写了一篇关于 "JS日历控件" 的文章 , 当时只支持 年月日 的日历控件,现在优化如下: 1. 在原基础上 支持 yyyy ...
 - JQuery日历控件
		
日历控件最后一弹——JQuery实现,换汤不换药.原理一模一样,换了种实现工具.关于日历的终于写完了,接下来研究研究nodejs.嗯,近期就这点事了. 同样还是将input的id设置成calendar ...
 - javascript日历控件——纯javascript版
		
平时只有下班时间能code,闲来写了个纯javascript版.引用该calendar.js文件,然后给要设置成日历控件的input的id设置成calendar,该input就会变成日历控件. < ...
 - IOS自定义日历控件的简单实现(附思想及过程)
		
因为程序要求要插入一个日历控件,该空间的要求是从当天开始及以后的六个月内的日历,上网查资料基本上都说只要获取两个条件(当月第一天周几和本月一共有多少天)就可以实现一个简单的日历,剩下的靠自己的简单逻辑 ...
 - 【转】【WebDriver】不可编辑域和日历控件域的输入 javascript
		
http://blog.csdn.net/fudax/article/details/8089404 今天用到日历控件,用第一个javascript执行后页面上的日期控件后,在html中可以看到生效日 ...
 - javascript日历控件
		
以前要用到日历控件都是直接从网上下载一套源码来使用,心里一直有个梗,就是想自己动手写一个日历控件,最近刚好来了兴趣,时间上也允许,于是自己摸索写了一个,功能还算完善,界面就凑合了.可能最值得说的一点就 ...
 - 用MVC的辅助方法自定义了两个控件:“可编辑的下拉框控件”和“文本框日历控件”
		
接触MVC也没多长时间,一开始学的时候绝得MVC结构比较清晰.后来入了门具体操作下来感觉MVC控件怎么这么少还不可以像ASP.net form那样拖拽.这样设计界面来,想我种以前没学过JS,Jquer ...
 - Jquery自定义扩展方法(二)--HTML日历控件
		
一.概述 研究了上节的Jquery自定义扩展方法,自己一直想做用jquery写一个小的插件,工作中也用到了用JQuery的日历插件,自己琢磨着去造个轮子--HTML5手机网页日历控件,废话不多说,先看 ...
 - Selenium2+python自动化25-js处理日历控件(修改readonly属性)
		
前言 日历控件是web网站上经常会遇到的一个场景,有些输入框是可以直接输入日期的,有些不能,以我们经常抢票的12306网站为例,详细讲解如何解决日历控件为readonly属性的问题. 基本思路:先用j ...
 
随机推荐
- 缓存淘汰算法之LRU
			
1. LRU1.1. 原理 LRU(Least recently used,最近最少使用)算法根据数据的历史访问记录来进行淘汰数据,其核心思想是“如果数据最近被访问过,那么将来被访问的几率也更高”. ...
 - 第4章 jQuery中的事件和动画
			
4.1 jQuery中的事件 4.1.1 加载DOM jQuery就是用 `$(document).ready()方法来代替传统JavaScript的window.onload方法的. 1.执行时机 ...
 - 20169219《Linux内核原理与分析》第八周作业
			
网易云课堂学习 task_struct数据结构 struct task_struct { volatile long state;进程状态 void *stack; 堆栈 pid_t pid; 进程标 ...
 - PLSQL连接Oracle11g 64位
			
目前plsql只有32位的,而Oracle11则是64位的,想要连接需要下载这个: 打开plsql,在Tools-->Prefences里面设置,如下图: 设置Oracle的主目录:下载文件解压 ...
 - Android消息传递之EventBus 3.0
			
Android消息传递之EventBus 3.0使用详解 http://www.cnblogs.com/whoislcj/p/5595714.html EventBus 3.0进阶:源码及其设计模式 ...
 - Insus Paging Utility Version 2
			
Insus.NET对GridView或是DataList分页,都是使用自己的分页组件:http://www.cnblogs.com/insus/archive/2009/03/19/1417102.h ...
 - 检测评价函数 IOU
			
在目标检测的评价体系中,有一个参数叫做 IoU(intersection-over-union),简单来讲就是模型产生的目标窗口和原来标记窗口的交叠率.具体我们可以简单的理解为: 即检测结果(Dete ...
 - phpstrom 下载及phpStudy环境配置
			
1.下载phpstudy 2.打开 3. 4. 5.网站网址 项目路径 新增 host映射 PHP富文本编辑器 6.https://jingyan.baidu.com/articl ...
 - Oracle修改监听IP地址
			
oracle 11g断网安装时,没有检测net的功能,所以安装完后,netstat -an 发现自动监听的是127.0.0.1:1521,这样安装完成后,其他的主机根本无法连接,是什么原因呢? 排错后 ...
 - luogu1447 [NOI2010]能量采集 莫比乌斯反演
			
link 冬令营考炸了,我这个菜鸡只好颓废数学题了 NOI2010能量采集 由题意可以写出式子: \(\sum_{i=1}^n\sum_{j=1}^m(2\gcd(i,j)-1)\) \(=2\sum ...