[引]雅虎日历控件 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 ...
随机推荐
- 《Head First Servlets & JSP》-6-会话管理-listener etc. demo
工程结构 上下文参数示例 示例程序展示了如何从上下文读取参数,并在上下文监听器中生成属性对象和在上下文中设置属性. 建立一个简单的JavaBean对象作为属性:Dog.java package com ...
- Elasticsearch suggester搜索建议初步
环境 Elasticsearch 2.3.5 Elasticsearch-ik-plugin 实现 搜索建议的对象 假设有以下两个json对象,需要对其中tags字段进行搜索建议: //对象Produ ...
- 多线程学习-基础( 九)线程同步Synchronized关键字
一.线程同步1.synchronized关键字的作用域有二种:(1)某个对象实例内:synchronized aMethod(){}可以防止多个线程同时访问这个对象的synchronized方法(如果 ...
- [转]Oracle截取字符串相关函数
转至:http://www.cnblogs.com/qmfsun/p/4493918.html 1.instr(sourceString,destString,start,appearPosition ...
- 关于windows2012-远程复制粘贴无效的解决方法
1:在远程桌面中右键点击,选择启动任务管理器,杀掉进程 2:重启服务即可:
- webapi 返回json
web api 默认的已 xml 格式返回数据 现在开发一般都是以 json 格式为主 下面配置让 webapi 默认返回 json ,在需要返回 xml 时只需要加一个查询参数 datatype=x ...
- tomcat的日志文件权限与启动用户的权限不一致
用户work的文件权限(umask=0002)为 u=rwx,g=rwx,o=rx 但是tomcat的日志文件的权限却是:为什么会不一样呢? 这是因为tomcat在启动(catalina.sh)时会重 ...
- ubuntu - 安装软件问题
problem & solution 问题1 - E: 无法定位软件包 @原因(1) - 没有添加相应软件的镜像源(软件源) 解决方案 用 gedit/vi/vim - 在 /etc/a ...
- linux 学习文档
1.nginx中文文档 http://www.nginx.cn/doc/
- 线段树 SP1043 GSS1 - Can you answer these queries I
SP1043 GSS1 - Can you answer these queries I 题目描述 给出了序列A[1],A[2],-,A[N]. (a[i]≤15007,1≤N≤50000).查询定义 ...