js里边onrenderjs img.completee是什么意思

[ExtJS学习笔记]第七节 Extjs的组件components及其模板事件方法学习
一个EXT JS的应用程序的UI用户界面是有一个或者多个部件构成的组件。所有的组件都是Ext Component类的子类,允许它们参与自动化生命周期管理包括实例化,渲染,大小,定位还有销毁。Ext JS提供了一系列有用的
一个EXT JS的应用程序的UI用户界面是有一个或者多个部件构成的。所有的组件都是ponent类的子类,允许它们参与自动化生命周期管理包括实例化,渲染,大小,定位还有销毁。Ext JS提供了一系列有用的组件,任何组件可以很容易地扩展到创建一个定制的组件。
组件的继承关系
容器是一个特殊的组件类型,它可以包含其他组件。一个典型的应用程序是有许多嵌套的组件像树状结构哪有的组件继承结构。容器负责管理他们的子组件的生命周期,包含创建,渲染,大小还有位置和销毁。一个典型的应用程序的组件继承从顶层的Viewport开始,它还有其它的容器嵌套在里面。
子组件通过使用容器的items配置增加到容器中,下面的例子使用Ext.create()创建初始化了两个面板,然后作为Viewport的子组件增加到Viewport中。
var childPanel1 = Ext.create('Ext.panel.Panel', {
title: 'Child Panel 1',
html: 'A Panel'
var childPanel2 = Ext.create('Ext.panel.Panel', {
title: 'Child Panel 2',
html: 'Another Panel'
Ext.create('Ext.container.Viewport', {
items: [ childPanel1, childPanel2 ]
容器使用布局管理器来管理组件的大小还有位置,想要获取关于布局的更多信息,请访问 布局和容器指南
XTypes和懒加载
每一个组件都有一个符号名叫做xtype。像Ext.panel.Panel就有一个xtype名叫做&panel&, 组件的API文档 列出了所有的组件的xtype。上面的例子展示了如何增加一个已经存在的组件到一个容器中。然而,在大型的应用程序中,着不是理想的,因为不是所有的组件都要被实例化,一些组件可能永远不需要被初始化,这取决于你的应用程序。例如,一个使用tab panel的应用程序只需要获取用户点击之后的那个tab的内容。这就是xtypes派上用处的地方通过允许容器的孩子在前置进行配置,需要的时候才进行实例化。
下面的示例代码演示了懒实例化和呈现一个使用选项卡面板的容器的子组件。每个标签都有一个事件侦听器,显示一个警告标签时呈现。
Ext.create('Ext.tab.Panel', {
renderTo: Ext.getBody(),
height: 100,
width: 200,
// Explicitly define the xtype of this Component configuration.
// This tells the Container (the tab panel in this case)
// to instantiate a Ext.panel.Panel when it deems necessary
xtype: 'panel',
title: 'Tab One',
html: 'The first tab',
listeners: {
render: function() {
Ext.MessageBox.alert('Rendered One', 'Tab One was rendered.');
// xtype for all Component configurations in a Container
title: 'Tab Two',
html: 'The second tab',
listeners: {
render: function() {
Ext.MessageBox.alert('Rendered One', 'Tab Two was rendered.');
允许这段代码,会立即产生第一个tab的alert弹出框。这个发生是因为这是默认的tab页签,所以容器就立即调用病实例化容器的Tab Panel。
第二个tab框直到点击的时候才会弹出,这就显示了需要的时候才会渲染,就是说tab页签激活的时候才会通知render事件。
显示和隐藏
所有的组件都是在show和hide方法中构造的。用来隐藏组件的默认的css方法是“display:none”但是通过hidemode配置的时候就有所变化了:
var panel = Ext.create('Ext.panel.Panel', {
renderTo: Ext.getBody(),
title: 'Test',
html: 'Test Panel',
hideMode: 'visibility' // use the
visibility property to show and hide this
panel.hide(); // hide the component
panel.show(); // show the component
浮动组件是通过css绝对路径将文档放置在外的,并且不在参与组件的容器的布局的。有些组件像Windows是默认的浮动,所有的组件都可以通过配置来实现浮动:
var panel = Ext.create('Ext.panel.Panel', {
width: 200,
height: 100,
floating: true, // make this panel an absolutely-positioned floating component
title: 'Test',
html: 'Test Panel'
上述代码初始化了一个panel,但是没有渲染。正常情况下,一个组件或者有一个renderTo配置或者当做一个子组件增加到组件的容器中,但是当是浮动组件的时候,都不需要了。浮动组件会在第一次调用show方法的时候被渲染
panel.show(); // render and show the floating panel
下面有一些对浮动组件来说可以进行配置的一些方法
1.draggable:可以拖动屏幕周围浮动组件。
2.shadow:定制的外观浮动组件的影子。
3.alignTo:将浮动组件指定到特定的元素。
4.center() 将组件浮动到组件的中心
创建自定义组件
成分或者扩展
当创建一个新的UI类的时候,该类必须做出决定是否应该拥有一个组件的一个实例,或扩展组件
根据功能需要继承一个最近的基类是被推荐的。这是因为EXT JS提供的自动生命周期管理包含了当需要的时候自动渲染,自动大小,自动调整位置当通过布局管理的时候,也会自动的从容器中移除和销毁。
通过组建创建新类比较容易,不推荐使用一个新的类拥有一个组件在外部去渲染和管理。
类 让扩展extjs框架变得非常容易。Ext.Base是所有Ext JS类的构建块,原型和这个类的静态成员被其他类继承。
尽管你可以再低水平的情况下增加一个方法,但是开发人员在通常情况下会想通过高一点的继承链来开始。
下面这个例子创建了一个ponent的子类:
Ext.define('ponent', {
extend: &#ponent',
newMethod : function() {
这个例子创建了一个新的类&ponent&,它继承了ponent的所有方法属性等。
EXT JS使用 模板方法模式 代表子类,行为。
这意味着,在继承链中的每一个类都可能贡献一个额外的逻辑组件的生命周期中的某些阶段。每一个类实现自己的独有的行为,并且允许其他继承自这个类的实现自己特有的逻辑。
典型例子就是 渲染 方法,render 是定义在Component类中的一个方法,它对初始化组件的呈现阶段生命周期负责。render不能被重写,但是可以调用onRender方法在处理子类实现的时候可以调用来实现自己的特有属性方法。每一个onRender方法必须调用父类的onRender方法在贡献自己额外逻辑的时候。
下面的表格展示了onRender模板方法的功能。
render方法被调用(通过布局管理器来实现的)。这个方法不能被重写也是通过Ext基类实现的,它调用this.onRender方法,这个方法实现了当前子类(如果被实现了的话)。这个就调用父类的版本,以此类推。最终,每个类贡献了自己的功能,控制返回render方法。
下面是一个组件子类实现onRender的例子:
Ext.define('ponent', {
extend: &#ponent',
onRender: function() {
this.callParent(arguments); // call the superclass onRender method
// perform additional rendering tasks here.
需要值得注意的是,许多模板方法都有自己对应的事件,例如渲染事件,是在渲染事件出发的时候执行。然而,当子泪花的时候,它必须使用模板方法在重要声明周期阶段执行类逻辑而不是事件。事件可以通过来停止或者暂停。
下面是一些子类可以实现的组件的模板方法:
initComponent:这个方法被类构造方法唤醒,用来初始化数据,设置属性,附加事件处理。
beforeShow:在组件显示之前被调用
onShow: 允许添加行为操作,在超类的onShow方法被调用之后就组件就可见了。
afterShow: 方法在组件被显示之后调用。
onShowComplete:这个方法在afterShow完成之后被调用
onHide:在隐藏的时候可以增加一些操作,调用超类的onHide方法之后,组件就看不见了。
afterHide:组件隐藏之后的事件处理
onRender:渲染的时候执行的事件
afterRender:渲染完成之后可以增加的额外操作。在你这个阶段,组件的元素已经根据配置或者css雷鸣增加了类型,并且将会被配置可见性和启用状态。
onEable:组件可用性,调用超类的这个事件的时候,组件就可以使用了
onDisable:组件不可用处理的时候的事件。
onAdded:当组件被增加的时候,组件被增加到容器的时候。在这个阶段,组件在父类容器的子条目集合中,当调用超类的这个方法之后,容器就是被展现,如果有引用,引用也会被设置。
onRemoved:被移除的时候的事件。这时候,组件以及从父容器之中移除了,但是还没有销毁。调用超类的这个方法之后,容器就不会被展现了。
onResize:大小变化的时候的调用事件
onPosition:位置变化的时候调用的事件
onDestroy:销毁的时候的事件
beforeDestroy:销毁之前
afterSetPosiotion:设置位置之后
afterComponentLayout:组件布局之后
beforeComponentLayout:组件布局之前
我们该扩展哪个类
选择一个最好的继承类是一个效率的问题,功能基类必须要提供的。有一种趋势就是总是继承Ext.panel.Panel当你设置UI组件的时候,这些组件需要被渲染和管理的时候。
Panel类有如下能力:
Header Tools
Footer Buttons
Top toolbar
Buttom toolbar
Containig and managing child Components
如果这些不需要,那么使用Panel类就是一种资源浪费。
如果需要的组件UI不需要包含其他组件,那就是,如果只是封装HTML执行某种形式的需求,那么扩展ponent是合适的。举例来说,下面这个类是一个组件包装了HTML的图片元素,允许通过图片的src属性来设置和获取。在加载的时候也会有方法被触发。
Ext.define('Ext.ux.Image', {
extend: &#ponent', // ponent
alias: 'widget.managedimage', // this component will have an xtype of 'managedimage'
tag: 'img',
src: Ext.BLANK_IMAGE_URL,
cls: 'my-managed-image'
// Add custom processing to the onRender phase.
// Add a 'load' listener to the element.
onRender: function() {
this.autoEl = Ext.apply({}, this.initialConfig, this.autoEl);
this.callParent(arguments);
this.el.on('load', this.onLoad, this);
onLoad: function() {
this.fireEvent('load', this);
setSrc: function(src) {
if (this.rendered) {
this.el.dom.src =
this.src =
getSrc: function(src) {
return this.el.dom.src || this.
使用如下:
var image = Ext.create('Ext.ux.Image');
Ext.create('Ext.panel.Panel', {
title: 'Image Panel',
height: 200,
renderTo: Ext.getBody(),
items: [ image ]
image.on('load', function() {
console.log('image loaded: ', image.getSrc());
image.setSrc('/img/sencha-large.png');
这只是一个例子给展示而已,你想使用的话,应该结合实际应用程序来设计。
Container容器
如果组件包含其他组件,那么就选容器比较适合了。在面板级别,需要重点记忆的是,Ext.layout.container.Container不是用来被渲染和管理子组件的。
容器拥有下面这些方法:
onBeforeAdd:子组件增加的时候这个方法被调用。通过了新组件,可以用来修改组件,或准备容器。返回false中止添加操作。
onAdd:组件被增加完成的时候调用。它是通过组件已被添加。这种方法可以用于更新任何内部结构可能依赖于状态的子元素。
onRemove:它是通过组件已被添加。这种方法可以用于更新任何内部结构可能依赖于状态的子元素。
beiforeLayout:这个方法被调用之前容器已经制定了(如果需要)并呈现它的子组件。
afterLayout:调用该方法后,集装箱已经制定了(如果需要)并呈现它的子组件。
如果UI界面需要头信息,底部信息,工具条,那么Ext.panel.Panel就是一个合适的选择。
重要的是:一个面板是一个容器。重要的是要记住,布局是用于呈现和管理子组件。
这类扩展Ext.panel。面板通常非常特定于应用程序的,一般用于聚合其他UI组件(通常是容器,或表单字段)配置布局,并提供操作手段所包含的组件通过控制tbar bbar。
面板拥有如下的模板方法:
afterCollapse:当折叠的时候被调用
afterExpand:当展开的时候被调用
onDockedAdd:当停靠的时候调用
ondockedRemove当停靠移除的时候调用。Angular.js After Render - JSFiddle
Test your JavaScript, CSS, HTML or CoffeeScript online with JSFiddle code editor.
online javascript editor, testing javascript online, online ide, online code editor, html, css, coffeescript, scss online editor
JavaScript
Embed code :
<textarea class="embedCode" data-view="embedded" data-pattern-value=''>
No autoresizing to fit the code
Render blocking of the parent page
Diff between the saved and locally drafted fiddle:
Auto-close HTML tags
Show line numbers
Enable line wrapping
Indent with tabs
Indent size:
Sublime Text
Fiddle Meta
External Resources 3
AJAX Requests
/echo simulates AJAX calls:
JSON: /echo/json/
JSONP: //jsfiddle.net/echo/jsonp/
HTML: /echo/html/
XML: /echo/xml/
for more info.
Legal, Credits and Links
Created and maintained by
All code belongs to the poster and no license is enforced.
JSFiddle or its authors are not responsible or liable for any loss or damage of any kind during the usage of provided code.
Like JSFiddle?
Keep us running by whitelisting JSFiddle in your ad blocker.
We're serving quality, tech-related ads only.
Thank you!
&div ng-app=&curlingApp& &
&div id=&curling-field& ng-controller=&curlingAppCtrl&&
&button ng-click=&addStone($event)& &Add Stone&/button&
&div id=&field&&
&!-- directive &displayStone&-&&display-stone& --&
&div class=&stone& ng-repeat=&s in stones& display-stone&&/div&
&div id=&goal&&&/div&
var Stone = (function() {
function Stone(num) {
this.num =
//Controller
var curlingApp = angular.module(&curlingApp&,[]);
curlingApp.controller(&curlingAppCtrl&,function($scope){
$scope.title
= &Curling Competition&;
$scope.stones = [];
$scope.addStone = function($event){
var index = $scope.stones.
$scope.stones.push(new Stone(index))
curlingApp.directive(&displayStone&,function(){
return function(scope, element, attrs){
//scope=local scope , element is dom and attrs is attributes of it.
$(element[0]).draggable();
$(function(){
$(&#goal&).droppable({
drop:function(event,ui){
target = $(this).addClass(&stone-in&);
setTimeout(function(){
target.removeClass(&stone-in&);
height:330
background-color:
background-color:
#goal.stone-in{
background-color:
background-color:
border-radius:15
XHTML 1.0 Strict
XHTML 1.0 Transitional
HTML 4.01 Strict
HTML 4.01 Transitional
HTML 4.01 Frameset
JavaScript
CoffeeScript
JavaScript 1.7
TypeScript
Frameworks & Extensions
AngularJS 2.0.0-alpha.47
AngularJS 1.4.8
AngularJS 1.2.1
AngularJS 1.1.1
Bonsai 0.4.1
Brick edge
Dojo (nightly)
Dojo 1.10.4
Dojo 1.9.7
Dojo 1.8.10
Dojo 1.7.8
Dojo 1.6.2
Dojo 1.5.3
Ember (latest)
Enyo (nightly)
Enyo 2.7.0
Enyo 2.5.1
Enyo 2.4.0
Enyo 2.2.0
Enyo 2.0.1
ExtJS 6.2.0
ExtJS 5.1.0
ExtJS 5.0.0
ExtJS 4.2.0
ExtJS 4.1.1
ExtJS 4.1.0
ExtJS 3.4.0
ExtJS 3.1.0
FabricJS 1.7.1
FabricJS 1.5.0
FabricJS 1.4.0
FabricJS 1.2.0
FabricJS 0.9
Inferno 1.0.0-beta9
jQuery (edge)
jQuery 3.1.1
jQuery 3.1.0
jQuery 3.0.0
jQuery 2.2.4
jQuery 2.2.3
jQuery 2.2.2
jQuery 2.2.1
jQuery 2.2.0
jQuery 2.1.3
jQuery 1.9.1
jQuery Slim 3.1.1 Slim
jQuery Slim 3.1.0 Slim
jQuery Slim 3.0.0 Slim
JSBlocks (edge)
jTypes 2.1.0
KineticJS 4.3.1
KineticJS 4.0.5
Knockout.js 3.4.0
Knockout.js 3.0.0
Knockout.js 2.3.0
Knockout.js 2.2.1
Knockout.js 2.1.0
Knockout.js 2.0.0
Lo-Dash 2.2.1
Minified 1.0 beta1
MithrilJS 0.2.0
Mootools (nightly)
Mootools 1.6.0 (compat)
Mootools 1.6.0
Mootools 1.5.2 (compat)
Mootools 1.5.2
Mootools 1.5.1
Mootools 1.5.0
Mootools 1.4.5 (compat)
Mootools 1.4.5
Mootools 1.3.2 (compat)
Mootools 1.3.2
No-Library (pure JS)
OpenUI5 (latest, mobile)
Paper.js 0.22
Pixi 4.0.0
Pixi 3.0.11
Processing.js 1.4.7
Processing.js 1.4.1
Processing.js 1.3.6
Processing.js 1.2.3
Prototype 1.7.3
Prototype 1.7.2
Prototype 1.7.1
Prototype 1.6.1.0
qooxdoo 2.1
qooxdoo 2.0.3
RactiveJS 0.7.3
Raphael 2.1.0
Raphael 1.5.2 (min)
Raphael 1.4
React 0.14.3
React 0.9.0
React 0.8.0
React 0.4.0
React 0.3.2
RightJS 2.3.1
RightJS 2.1.1
Shipyard (nightly)
Shipyard 0.2
svg.js 2.1.1
The X Toolkit edge
Thorax 2.0.0rc6
Thorax 2.0.0rc3
Three.js r54
Underscore 1.8.3
Underscore 1.4.4
Underscore 1.4.3
Underscore 1.3.3
Vue (edge)
Vue 1.0.12
WebApp Install 0.1
YUI 3.17.2
YUI 3.16.0
YUI 3.14.0
YUI 3.10.1
YUI 2.8.0r4
Zepto 1.0rc1
onDomready
No wrap - in &head&
No wrap - in &body&
Framework &script> attribute
Normalized CSSjQuery Datepicker Reference
jQuery Datepicker Reference
that attaches a popup calendar to your input fields or shows an
inline calendar for selecting individual dates or date ranges.
This page provides a documentation reference for working
with the plugin v5.1.0.
for your own reference - just add jQuery JavaScript for full functionality.
datepicker plugin and download the code from there.
that you could
use as a basis for your own investigations.
Datepicker Settings
A separate datepicker instance is created for each targeted control:
$(selector).datepick();.
When applied to a div or span the datepicker
is rendered inline. Otherwise it appears as a popup on demand.
Each instance may have different settings, e.g.
$(selector).datepick({minDate: new Date()});
Alternately, you can specify the settings per control by adding a data-datepick attribute, e.g.
&input type="text" data-datepick="rangeSelect: true, minDate: 'new Date()'"/&
The datepicker functionality can only be applied once. Affected controls are flagged
with the is-datepick class and are not re-processed if targeted again.
command if you want to change settings after the initial setup.
Below are the settings that may be applied to each datepicker instance.
All are optional.
A note on Date - the JavaScript Date constructor expects
the year, month, and day as parameters. However, the month ranges from 0 to 11.
To make explicit what date is intended (does a month of 3 mean March or April?)
I specify the month from 1 to 12 and manually subtract the 1.
Thus the following denotes 25 December, 2014.
$(selector).datepick({minDate: new Date(, 25)});
NameTypeDefaultComments
pickerClassstring''
Any extra CSS class(es) to add to this datepicker instance.
By specifying a unique class you can individually target
datepicker instances with special styling.
$(selector).datepick({pickerClass: 'my-picker'});
Since 4.0.0.
showOnFocusbooleantrue
When true a popup datepicker appears for an input
field when it gains focus. When false you should
Since 4.0.0 - previously
incorporated into showOn.
showTriggerstring or element or jQuerynull
The element(s) that will trigger a popup datepicker to appear
when they are clicked. You can provide either the element itself,
a jQuery collection containing the element, a string selector for
the desired element, or a string version of the element.
The trigger is cloned and placed after the input field (taking
languages into account).
$(selector).datepick({showTrigger:
'&img src="img/calendar.gif" alt="Popup" class="trigger">'});
$(selector).datepick({showTrigger: '#myicon'});
Since 4.0.0 - previously you used
showOn, buttonText, buttonImage,
and buttonImageOnly.
showAnimstring'show'
The name of the animation to use when a popup datepicker appears
and disappears. The value can be one of the standard animations -
'show', 'fadeIn', or 'slideDown' - or any of the
(provided you have included the appropriate plugin).
Set this to '' for no animation.
$(selector).datepick({showAnim: 'fadeIn'});
$(selector).datepick({showAnim: 'clip'});
$(selector).datepick({showAnim: ''}); // Immediate
Since 3.7.3 - '' for no animation.
showOptionsobject{}
For jQuery UI animations you can specify any additional options
with this setting. For example, the clip animation can
be set to run horizontally instead of vertically.
$(selector).datepick({showAnim: 'clip',
showOptions: {direction: 'horizontal'}});
showSpeedstring or number'normal'
The speed at which the animation runs. Use one of the standard speeds -
'slow', 'normal', or 'fast' - or specify the duration in milliseconds.
$(selector).datepick({showSpeed: 'fast'});
$(selector).datepick({showSpeed: 1500});
Since 4.0.0 - previously
it was duration.
popupContainer
string or element or jQuerynull
The container for the popup datepicker, allowing you to control
where in the DOM the datepicker is appended. You can provide either
the element itself, a jQuery collection containing the element,
or a string selector for the desired element. It defaults to
the document body.
$(selector).datepick({popupContainer: '#mydiv'});
Since 4.0.0.
alignmentstring'bottom'
Control the alignment of a popup datepicker with respect to its input field.
Use one of the following values: 'bottom' for below or 'top' for above,
both of which are left- or right- aligned depending on the localisation
preference, or 'topLeft', 'topRight', 'bottomLeft', or 'bottomLeft'.
The first two options will reposition the datepicker if it does not
fit in the requested space.
Since 3.7.0.
fixedWeeksbooleanfalse
Set to true to always have six weeks shown, or
false to only show as many weeks as are needed.
This setting only applies to a datepicker for a single month as all
datepickers are always fixed.
Since 4.0.0.
calculateWeekfunction$.datepick. iso8601Week
A function to calculate the week of the year for a given date.
The date (Date) is passed as a parameter and the function returns
a number indicating the corresponding week of the year.
If set to null the built-in
calculation is used.
You should use the
to actually display the value.
$(selector).datepick({calculateWeek: myWeek,
renderer: $.datepick.weekOfYearRenderer});
function myWeek(date) {
return Math.floor(($.datepick.dayOfYear(date) - 1) / 7) + 1;
monthsToShownumber or number[2]1
The number of months to show in the datepicker. It may be expressed
as a single number of columns, or as an array of rows and columns.
$(selector).datepick({monthsToShow: 3});
$(selector).datepick({monthsToShow: [2, 3]});
Since 4.0.0 - previously
it was numberOfMonths.
Since 4.0.1 - mark first and last
months in each row with classes first and last.
monthsOffsetnumber or function0
When showing , this setting
indicates at which position the current month is shown, starting from
zero. If specified as a function, it accepts a date as its parameter
and returns the corresponding offset. The example
below shows three months with the current one in the middle.
$(selector).datepick({
monthsToShow: 3, monthsOffset: 1});
Since 4.0.0 - previously
it was showCurrentAtPos.
Since 4.0.6 - can be a function.
monthsToStepnumber1
The number of months to move when the
month commands are invoked.
Since 4.0.0 - previously
it was stepMonths.
monthsToJumpnumber12
The number of months to move when the
year commands are invoked.
Since 4.0.0 - previously
it was stepBigMonths.
useMouseWheelbooleantrue
is available and this setting is true then you can use the mouse
wheel to step through the months or years (with the Ctrl key).
If this setting is false then the mouse wheel has no effect
within the datepicker, even if the plugin is available.
Since 4.0.3.
changeMonthbooleantrue
Set to true to allow the month and year to be changed
via a drop-down selection on the first month shown in the datepicker.
Set to false to only allow changes via the various
Since 4.0.0 - previously
it only affected the month drop-down with changeYear
controlling the year drop-down.
yearRangestring'c-10:c+10'
Specify the range of years shown in the year drop-down.
The setting contains the start and end of the range separated by a colon (:).
Each limit may be an absolute year ('1980'), an offset from today ('-10' or '+10'),
or an offset from the currently selected date ('c-5' or 'c+5').
Place the maximum value first to have the list appear in descending order.
Set to 'any' to allow direct input of the year without selection
from a drop-down list. The default is to show 10 years before and
after the currently selected date.
Note that this setting does not restrict the dates that may be selected.
You should use the
settings to impose limits
on the dates that may be selected.
$(selector).datepick({yearRange: ''});
$(selector).datepick({yearRange: '1960:-18'});
$(selector).datepick({yearRange: 'c+10:c-10'}); // Descending
$(selector).datepick({yearRange: 'any'});
Since 3.7.3 - relative to today's year and combinations.
Since 4.0.0 - 'any'.
Since 4.0.3 - descending ranges.
shortYearCutoffstring or number'+10'
When a two-digit year format is used (see
this value helps determine the century for a given date.
If expressed as a number (0 to 99) it is the year beyond which
the century should be the last one instead of the current one.
If expressed as a string, it is converted to a number and added
to the current year before making the comparison above.
If set to -1 the year is always in the 1900s.
Since 3.5.2 - disable with -1.
showOtherMonthsbooleanfalse
Set to true to show the days in other months that
appear in the partial weeks before or after the current month.
selectOtherMonthsbooleanfalse
Set to true to allow the days in other months that
appear in the partial weeks before or after the current month to be selected.
This setting only applies if
$(selector).datepick({
showOtherMonths: true, selectOtherMonths: true});
Since 3.5.0.
Date or number or stringnull
Specify the date to show if no other date has been selected.
This may be specified as an actual date (Date), as a date string in the current
as a number of days relative to today,
or as a string of offsets and periods relative to today.
For the last use 'y' for years, 'm' for months, 'w' for weeks, or 'd' for days.
Multiple offsets may be combined in the one string.
Set to null for a default date of today.
$(selector).datepick({
defaultDate: new Date(, 26)});
$(selector).datepick({defaultDate: '01/26/2013'});
$(selector).datepick({defaultDate: +7});
$(selector).datepick({defaultDate: '+1m -1d'});
Since 3.7.0 - added date string.
booleanfalse
Set to true to automatically select the
when no other date has been selected.
$(selector).datepick({
defaultDate: '01/26/2013', selectDefaultDate: true});
Since 4.0.0 - previously
it was showDefault.
Date or number or stringnull
Specify the minimum date allowed to be selected.
This may be specified as an actual date (Date), as a date string in the current
as a number of days relative to today,
or as a string of offsets and periods relative to today.
For the last use 'y' for years, 'm' for months, 'w' for weeks, or 'd' for days.
Multiple offsets may be combined in the one string.
Set to null for no minimum.
$(selector).datepick({
minDate: new Date(, 25)});
$(selector).datepick({minDate: '12/25/2012'});
$(selector).datepick({minDate: -10});
$(selector).datepick({minDate: '-1m -15d'});
Since 3.7.0 - added date string.
Date or number or stringnull
Specify the maximum date allowed to be selected.
This may be specified as an actual date (Date), as a date string in the current
as a number of days relative to today,
or as a string of offsets and periods relative to today.
For the last use 'y' for years, 'm' for months, 'w' for weeks, or 'd' for days.
Multiple offsets may be combined in the one string.
Set to null for no maximum.
$(selector).datepick({
maxDate: new Date(, 25)});
$(selector).datepick({maxDate: '12/25/2013'});
$(selector).datepick({maxDate: +10});
$(selector).datepick({maxDate: '+1m +15d'});
Since 3.7.0 - added date string.
autoSizebooleanfalse
Set to true to resize the input field based on the maximum length of a
date in the current
Set to false to not change the field length.
Since 3.7.1.
rangeSelectbooleanfalse
Set to true to allow the selection of a date range in the
datepicker. The first selected date is the start of the range and the
second selected date is the end of the range.
A popup datepicker closes automatically on selection of the range end.
Set to false to select a single date.
rangeSeparatorstring' - '
Specify the separator shown between the two dates in a
multiSelectnumber0
Specify the maximum number of individual separate dates that may be selected
in the datepicker. Dates may be de-selected by clicked on them a second time.
A popup datepicker closes automatically on selection of the maximum number allowed.
Set to 0 to select a single date.
Since 3.6.0.
multiSeparatorstring','
Specify the separator shown between the dates selected in a
datepicker.
Since 3.6.0.
functionnull
Specify a callback function to provide additonal details about individual
dates shown in the datepicker. The function is called for each date displayed
and receives the date as a parameter (Date, with time portion set to 12 noon),
along with a Boolean indicating whether the date is in the main month being shown
(as opposed to being an extra day before or after the main month),
while this refers to the associated control.
It returns an object with the following attributes (all optional):
selectable (boolean) true if the date is selectable,
dateClass (string) any CSS class(es) t
title (string) a t
content (string) content for this date to replace the basic day number.
$(selector).datepick({
onDate: function(date, current) {
return !current ? {} :
{content: date.getDate() + '&br>&sub>' +
$.datepick.dayOfYear(date) + '&/sub>',
dateClass: 'showDoY'};
Since 4.0.0 - previously
beforeShowDay provided similar functionality.
Since 4.0.4 - time portion is 12 noon.
onShowfunctionnull
Specify a callback function to provide additonal functionality to a datepicker.
The function is called just before the datepicker is shown and receives the
completed datepicker division as a jQuery object and the current instance
settings as parameters, while this refers to the associated
control. It should update the datepicker division as necessary.
See the various examples in the
If you need multiple onShow callbacks, use the
function and pass the relevant handlers to it.
$(selector).datepick({
onShow: function(picker, inst) {
picker.find('td:even').addClass('alternate-dates');
Since 4.0.0.
onChangeMonthYearfunctionnull
Specify a callback function to be notified of changes to the month and year shown
in a datepicker. The function is called when the month/year changes and receives the
year and month as parameters, while this refers to the associated control.
If you need multiple onChangeMonthYear callbacks, use the
function and pass the relevant handlers to it.
$(selector).datepick({
onChangeMonthYear: function(year, month) {
$('#monthYear').text(month + '/' + year);
onSelectfunctionnull
Specify a callback function to be notified of date selection in a datepicker.
The function is called when each date is selected and receives the currently selected
dates (Date[]) as the parameter, while this refers to the associated control.
The array is empty if no dates have been selected.
All dates have their time portion set to 12 noon.
Note that when the start of a range is selected the dates array
contains two entries, with both being that starting date.
If you need multiple onSelect callbacks, use the
function and pass the relevant handlers to it.
$(selector).datepick({
onSelect: function(dates) {
$('#count').text('Selected ' + dates.length + ' date(s)');
var minDate = dates[0];
for (var i = 1; i & dates. i++) {
if (dates[i].getTime() & minDate.getTime()) {
minDate = dates[i];
$('#minDate').text($.datepick.formatDate(minDate));
Since 3.5.2 - added Date type parameter.
Since 4.0.0 - dates parameter only.
Since 4.0.4 - time portion is 12 noon.
onClosefunctionnull
Specify a callback function to be notified of a popup datepicker closing.
The function is called when the datepicker is closed (by any means)
and receives the currently selected dates (Date[]) as the
parameter, while this refers to the associated control.
The array is empty if no dates have been selected.
All dates have their time portion set to 12 noon.
Note that range selections always have two entries,
with both being the starting date if no end date has been selected.
If you need multiple onClose callbacks, use the
function and pass the relevant handlers to it.
$(selector).datepick({
onClose: function(dates) {
var selected = '';
for (var i = 0; i & dates. i++) {
selected += ',' + $.datepick.formatDate(dates[i]);
alert('Selected dates are: ' + selected.substring(1));
Since 3.5.2 - added Date type parameter.
Since 4.0.0 - dates parameter only.
Since 4.0.4 - time portion is 12 noon.
altFieldstring or element or jQuerynull
Specify another field to be updated in sync with the datepicker selections.
This and the following setting allow you to automatically show selected dates
in one format for the user, while maintaining a second field with a more
useful format for further processing. The alternate field may be specified
as either the element itself, a jQuery collection containing the element,
or a string selector for the desired element.
$(selector).datepick({dateFormat: 'DD, MM d, yyyy',
altField: '#isoDate', altFormat: 'yyyy-mm-dd'});
altFormatstringnull
Use in conjunction with the
setting to automatically maintain two different views of the selected date(s).
setting for the list of possible values.
constrainInputbooleantrue
Set to true to only allow the entry of characters specified by the
or false to allow any characters.
booleanfalse
Set to true to apply the
function to all command
. This allows
you to label commands with the dates to which they refer, for example the
could show the month to which they move.
Remember to quote (') any command text you do not want substituted.
$(selector).datepick({commandsAsDateFormat: true,
prevText: '& M', todayText: 'M y', nextText: 'M &'});
Since 4.0.0 - previously
it was navigationAsDateFormat.
commandsobject$.datepick. commands
tab for more details.
Since 4.0.0.
Datepicker Commands
The datepicker contains a series of commands that operate upon it, allowing these to
be customised or new commands added. Each command consists of an object with the
attributes shown below, and is added to the
are listed below.
Since 4.0.0.
NameTypeComments
textstring
The name of the
that provides the text value for this command.
statusstring
The name of the
that provides the tooltip (status) value for this command.
keystrokeobject
The keystroke that triggers this command. The object's attributes are:
keyCode (number) the numeric co
ctrlKey (boolean, optional) true if the Ctrl
key must be used in conjunction with the above keyCode;
altKey (boolean, optional) true if the Alt
key must be used in conjunction with the above keyCode;
shiftKey (boolean, optional) true if the Shift
key must be used in conjunction with the above keyCode.
enabledfunction
The function that indicates whether the command can be invoked at present.
It takes the current instance settings as a parameter,
while this is the associated target control.
It returns true if the command may be executed
or false if it may not.
The function that provides a target date for this command. For example,
the target date for the
command is the first day
of the previous month. It takes the current instance settings as a parameter,
while this is the associated target control. It returns a Date
if an appropriate date can be determined or null if not.
actionfunction
The function that implements the action for this command.
It takes the current instance settings as a parameter,
while this is the associated target control.
Standard Commands
The standard commands defined by the datepicker are shown below
and are available as $.mands.
These may be positioned in the datepicker by including the
'{link:name}' or '{button:name}' substitution points in the
where name is the command name below. Commands can be invoked on a datepicker with
NameTextStatusKeystroke
EnabledDateAction
If not at the
First day of previous month
Move to the previous month (depending on the
Ctrl+Page Up
If not at the
First day of 12 months ago
Move to 12 months ago (depending on the
If not at the
First day of next month
Move to the next month (depending on the
Ctrl+Page Down
If not at the
First day of 12 months ahead
Move to 12 months ahead (depending on the
If not outside
First selected date or today
Move to the month of the first selected date, or today if no date has been selected
If not outside
TodayMove to today's month
-Clear any selected dates and close a popup datepicker
-Close a popup datepicker
If not at the
One week agoMove to the previous week
If not at the
One day agoMove to the previous day
Ctrl+Right
If not at the
One day aheadMove to the next day
If not at the
One week aheadMove to the next week
Datepicker Localisation
These settings comprise the
that may be localised by a
They can be overridden for individual instances:
$(selector).datepick({prevText: '&'});
NameTypeDefaultComments
monthNamesstring[]
['January', 'February', 'March', 'April', 'May', 'June',
'July', 'August', 'September', 'October', 'November', 'December']
The full names of the months.
monthNamesShortstring[]
['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
The abbreviated names of the months.
dayNamesstring[]
['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday']
The full names of the days of the week, starting from Sunday.
dayNamesShortstring[]
['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat']
The abbreviated names of the days of the week, starting from Sunday.
dayNamesMinstring[]
['Su', 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa']
The minimal names of the days of the week, starting from Sunday.
string'mm/dd/yyyy'
Specify the format applied to the selected dates. This may be any combination
of the values below. To use any of these characters without substitution
you must surround them in single quotes (').
d - day of the month (no leading zero)
dd - day of the month (two digit)
D - day name short
DD - day name long
o - day of the year (no leading zeros)
oo - day of the year (three digits)
- week of year (no leading zero)
ww - week of year (two digit)
m - month of the year (no leading zero)
mm - month of the year (two digit)
M - month name short
MM - month name long
yy - year (two digit)
yyyy - year (four digit)
J - Julian date
@ - Unix timestamp (secs since 01/01/1970)
! - Windows ticks (100ns since 01/01/0001)
'...' - literal text
'' - single quote
Or you can use one of the predefined formats from the datepicker:
ATOM - 'yyyy-mm-dd'
COOKIE - 'D, dd M yyyy'
FULL - 'DD, MM d, yyyy'
ISO_8601 - 'yyyy-mm-dd'
JULIAN - 'J'
RFC_822 - 'D, d M yy'
RFC_850 - 'DD, dd-M-yy'
RFC_1036 - 'D, d M yy'
RFC_1123 - 'D, d M yyyy'
RFC_2822 - 'D, d M yyyy'
RSS - 'D, d M yy'
TICKS - '!'
TIMESTAMP - '@'
W3C - 'yyyy-mm-dd'
$(selector).datepick({dateFormat: 'yyyy-mm-dd'});
$(selector).datepick({dateFormat:
'\'day\' d \'of\' MM \'in the year\' yyyy'});
$(selector).datepick({dateFormat: $.datepick.FULL});
firstDaynumber0
The number of the first day of the week shown in the datepicker,
with 0 being Sunday, 1 being Monday, etc.
rendererobject
The renderer used to generate the datepicker.
You can use one of the predefined renderers, define your own,
or extend an existing one with minor changes.
tab for more details.
$(selector).datepick({
renderer: $.datepick.weekOfYearRenderer});
$(selector).datepick({
renderer: $.extend({}, $.datepick.defaultRenderer,
{picker: $.datepick.defaultRenderer.picker.
replace(/\{link:clear\}/, '{button:clear}').
replace(/\{link:close\}/, '{button:close}')})});
Since 4.0.0.
prevTextstring'&Prev'
The display text for the
setting to format
the text to show date information.
$(selector).datepick({
prevText: '& M', commandsAsDateFormat: true});
prevStatusstring'Show the previous month'
The tooltip text for the
prevJumpTextstring'&&'
The display text for the
setting to format
the text to show date information.
Since 4.0.0 - previously
it was prevBigText.
prevJumpStatusstring'Show the previous year'
The tooltip text for the
Since 4.0.0 - previously
it was prevBigStatus.
nextTextstring'Next>'
The display text for the
setting to format
the text to show date information.
$(selector).datepick({
nextText: 'M >', commandsAsDateFormat: true});
nextStatusstring'Show the next month'
The tooltip text for the
nextJumpTextstring'&&'
The display text for the
setting to format
the text to show date information.
Since 4.0.0 - previously
it was nextBigText.
nextJumpStatusstring'Show the next year'
The tooltip text for the
Since 4.0.0 - previously
it was nextBigStatus.
currentTextstring'Current'
The display text for the
setting to format
the text to show date information.
currentStatusstring'Show the current month'
The tooltip text for the
todayTextstring'Today'
The display text for the
setting to format
the text to show date information.
todayStatusstring'Show today\'s month'
The tooltip text for the
clearTextstring'Clear'
The display text for the
clearStatusstring'Clear all the dates'
The tooltip text for the
closeTextstring'Close'
The display text for the
closeStatusstring'Close the datepicker'
The tooltip text for the
yearStatusstring'Change the year'
The tooltip text for the year drop-down.
earlierTextstring'&#160;&#160;▲'
The display text for previous years in the year drop-down.
Since 5.0.1.
laterTextstring'&#160;&#160;▼'
The display text for following years in the year drop-down.
Since 5.0.1.
monthStatusstring'Change the month'
The tooltip text for the month drop-down.
weekTextstring'Wk'
The display text for the week of the year column header.
weekStatusstring'Week of the year'
The tooltip text for the week of the year column header.
dayStatusstring'Select DD, M d, yyyy'
The tooltip text for selectable days. The
function is applied to the value before use.
Since 4.0.0 - previously
it was dateStatus.
defaultStatusstring'Select a date'
The tooltip text for areas of the datepicker not covered by one of the other statuses above.
Since 4.0.0 - previously
it was initStatus.
isRTLbooleanfalse
Set to true to indicate that this language runs right-to-left.
Datepicker Renderers
Renderers allow you to use a templating mechanism to construct the datepicker
for display. They are assigned to a datepicker instance as the
setting, one of the localisation settings.
Since 4.0.0.
You control the structure of the datepicker, the placement
of controls within it, and the CSS styling that is applied to it.
Substitution points of the form '{xxx}' indicate where standard content
should be inserted.
There is a default renderer defined in the datepick module
and several alternative renderers in the datepick.ext module.
These are all described .
If you define your own custom render it must contain all of the attributes
described below. Alternatively you can tweak an existing renderer:
$(selector).datepick({renderer: $.extend(
{}, $.datepick.defaultRenderer,
{picker: $.datepick.defaultRenderer.picker.
replace(/\{link:today\}/, '{link:current}')})});
NameTypeComments
The following substitution points may be used anywhere within
the renderer structure:
'{l10n:name}' to insert the localised value for name;
'{link:name}' to insert a link for command name;
'{button:name}' to insert a button for command name;
'{popup:start}...{popup:end}' to delimit sections that only
'{inline:start}...{inline:end}'
to delimit sections that only
appear in an inline datepicker.
The overall structure of the datepicker. Use:
'{months}' to insert the generated content for
all of the shown months.
The structure of a single row of months in the datepicker. Use:
'{months}' to insert the generated content for
all of the months in that row.
The structure of a single month in the datepicker. Use:
'{monthHeader:dateFormat}' to insert the header for that month
using the specified , which is optional and defaults to 'MM yyyy';
'{weekHeader}' to insert the li
'{weeks}' to insert the generated content for
all of the weeks in the month.
The structure of a single list of days in a week. Use:
'{days}' to insert the generated content for
all of the days in the week.
The structure of a single day header. Use:
'{day}' to insert the generated content for
the name of the day.
The structure of a single week in a month. Use:
'{days}' to insert the generated content for
'{weekOfYear}' to insert the generated content for
the week of the year number.
The structure of a single day in a month. Use:
'{day}' to insert the generated content for the number of the day.
Selectable days are enclosed in a link (a) while
non-selectable days are wrapped in a span.
monthSelector
The jQuery selector, relative to a wrapper around
, for a single
daySelector
The jQuery selector, relative to a wrapper around
, for a single
Any CSS class(es) to apply to a datepicker using a right-to-left language.
multiClass
Any CSS class(es) to apply to a datepicker showing more than one month.
defaultClass
Any CSS class(es) to apply to selectable days.
selectedClass
Any CSS class(es) to apply to selected days.
highlightedClass
Any CSS class(es) to apply to the cursor day.
todayClass
Any CSS class(es) to apply to today.
otherMonthClass
Any CSS class(es) to apply to days from other months.
weekendClass
Any CSS class(es) to apply to days on weekends.
commandClass
Any CSS class(es) to apply to command links or buttons.
It is also used as a prefix (followed by '-') for an
additional class based on the command name.
commandButtonClass
Any CSS class(es) to apply to command buttons only.
commandLinkClass
Any CSS class(es) to apply to command links only.
disabledClass
Any CSS class(es) to apply to disabled command links or buttons.
Standard Renderers
The standard renderers are listed below. Each is accessible within
the $.datepick object via the given name.
NameModuleComments
defaultRendererdatepick
The standard renderer. Match it with the standard datepicker CSS.
weekOfYearRendererdatepick.ext
The standard renderer enhanced to include a column for week of the year.
Match it with the standard datepicker CSS.
themeRollerRendererdatepick.ext
A renderer using a similar structure to the default one, but with the standard
classes for styling.
Match it with one of the ThemeRoller CSS themes.
themeRollerWeekOfYearRendererdatepick.ext
The ThemeRoller renderer enhanced to include a column for week of the year.
Match it with one of the ThemeRoller CSS themes.
Datepicker Globals
NameTypeDefaultComments
commandsobject[]
The set of commands for the datepicker and the default value for the
Entries are indexed by the command name.
Each entry is an object with the properties shown on the
You could, for example, change the keystrokes assigned to certain commands:
var altCommands = $.extend(true, {}, $.mands); // Clone
altCommands.prevJump.keystroke = {keyCode: 33, altKey: true}; // Alt+PageUp
altCommands.nextJump.keystroke = {keyCode: 34, altKey: true}; // Alt+PageDown
$('#keystrokePicker').datepick({commands: altCommands,
showTrigger: '#myicon'});
Since 4.0.0.
regionalOptionsobject[]
The set of regional settings for the datepicker fields. Entries are indexed
by the country/region code with '' providing the default (English) settings.
Each entry is an object with the properties shown on the
Language packages load new entries into this array and
automatically apply them as global defaults.
&script type="text/javascript"
src="jquery.datepick-fr.js"&&/script&
If necessary, you can then revert to the default language settings with
$.datepick.setDefaults($.datepick.regionalOptions['']);
and apply the language settings to individual fields with code like the following:
$('#frenchDatepicker').datepick($.datepick.regionalOptions['fr']);
Check out the list of available .
Since 5.0.0 - previously called regional.
Functions and Commands
SignatureReturnsComments
$.datepick.setDefaults(settings)Datepicker object
Update the default
to use with all datepicker instances.
settings (object) is the collection of new settings.
$.datepick.setDefaults({dateFormat: 'yyyy-mm-dd'});
$(selector).datepick('option', settings)jQuery object
Update the
for the datepicker instance(s) attached to the given field(s).
settings (object) is the collection of new settings.
$(selector).datepick('option', {firstDay: 1});
$(selector).datepick('option', name, value)jQuery object
for the datepicker instance(s) attached to the given field(s).
name (string) is the
value (any) is the new value, or null to reset to the default.
$(selector).datepick('option', 'firstDay', 1);
$(selector).datepick('option', name)object or any
Retrieve one or all of the current
for the first datepicker instance attached to the given field(s).
name (string, optional) the name of the
omit for all settings.
var settings = $(selector).datepick('option');
var firstDay = $(selector).datepick('option', 'firstDay');
Since 3.5.2.
Since 4.0.0 - previously it was part of the 'option' command.
Since 4.1.0 - previously you used the 'options' command.
$(selector).datepick('destroy')jQuery object
Remove the datepicker functionality from the given field(s).
$(selector).datepick('enable')jQuery object
Enable the datepicker for the given field(s) as well as the field itself.
$(selector).datepick('disable')jQuery object
Disable the datepicker for the given field(s) as well as the field itself.
$(selector).datepick('isDisabled')boolean
Determine whether the datepicker functionality has been disabled
for the first of the given field(s).
$(selector).datepick('show')jQuery object
Pop up the datepicker for the given field.
$(selector).datepick('hide')jQuery object
Hide the datepicker for the given field.
Retrieve the currently selected date(s) from the datepicker for the first given field.
An empty array is returned if no dates are selected.
All dates have their time portion set to 12 noon.
datepicker always returns two dates, being the start and end of the range.
var dates = $(selector).datepick('getDate');
Since 4.0.4 - time portion is 12 noon.
jQuery object
Set the currently selected dates for the given field(s).
dates (Date) is the new date, or (string) the date in the current
or (number) the number of days from today, or (string) a series of
amounts and periods from today,
or ([]) an array of any of these formats. Provide an empty array
to clear all dates or use the
Any dates in excess of those allowed by the datepicker are ignored.
$(selector).datepick('setDate', new Date(, 26));
$(selector).datepick('setDate', '01/26/2013');
$(selector).datepick('setDate', '+1m'); // Today + 1 month
$(selector).datepick('setDate', 7); // Today + 7 days
$(selector).datepick('setDate',
[new Date(, 26), '+1m', 7]);
Since 3.7.0 - added date string.
Since 3.7.1 - added relative to current.
Since 3.7.2 - omit dates to clear all dates.
$(selector).datepick('setDate', startDate, endDate)jQuery object
Set the currently selected
for the given field(s).
startDate (see above)
is the starting date for the date range.
endDate (see above) is the ending date for the date range.
$(selector).datepick('setDate',
new Date(, 26), new Date(, 26));
$(selector).datepick('setDate', 7, '+1m');
$(selector).datepick('clear')jQuery object
Clear the currently selected dates for the given field(s).
Since 4.0.0.
$(selector).datepick('isSelectable', date)boolean
Determine whether a date is selectable for this datepicker.
It checks against any , , and/or
options that have been set.
date (Date or string or number, optional) the date to check.
This may be specified as an actual date (Date), as a date string in the current
as a number of days relative to today,
or as a string of offsets and periods relative to today.
For the last use 'y' for years, 'm' for months, 'w' for weeks, or 'd' for days.
Multiple offsets may be combined in the one string.
Omit to use the currently selected date, or today if none selected.
Since 4.0.3.
$(selector).datepick('performAction', name)jQuery object
Execute a named
for a datepicker.
name (string) the name of the command.
$(selector).datepick('performAction', 'today');
Since 4.0.0.
$(selector).datepick('showMonth', year, month, day)jQuery object
Change the displayed month to a specified month and year.
If no month and year are given, today's month is shown.
year (number, optional) the year to show.
month (number, optional) the month (1-12) to show.
day (number, optional) the day to highlight initially -
if omitted it defaults to the previously highlighted day.
$(selector).datepick('showMonth', 2013, 1);
Since 4.0.0.
$(selector).datepick('changeMonth', offset)jQuery object
Change the displayed month by moving a number of months ahead or behind.
offset (number) the number of months to move.
$(selector).datepick('changeMonth', -6);
Since 4.0.0.
$(selector).datepick('changeDay', offset)jQuery object
Change the cursor day by moving a number of days ahead or behind.
offset (number) the number of days to move.
$(selector).datepick('changeDay', -14);
Since 4.0.0.
Retrieve the date associated with a particular day element
(a or span) within a datepicker.
element (element) the day element to extract the date from.
Since 4.0.0.
jQuery object
Select the date associated with a particular day element
(a or span) within a datepicker.
element (element) the day element to extract the date from.
Since 4.0.0.
$.datepick.multipleEvents(fns)function
Allow multiple event handlers to be triggered by a single callback.
The handlers are called in the order specified.
fns (function...) is the collection of event handlers.
$(selector).datepick({
onShow: $.datepick.multipleEvents(
$.datepick.changeFirstDay, $.datepick.showStatus)});
Since 4.0.0.
$.datepick.errorPlacement(error, element)-
Correctly places a validation error message after any trigger button or icon
(or before it if using a right-to-left localisation).
It should be assigned as the errorPlacement setting for the
Since 3.5.1 - only available with the validation extension.
Datepicker Extensions
The functions shown below are available through the datepick.ext module.
There are also several
available from this module.
SignatureReturnsComments
$.datepick.noWeekendsobject
Attach this function to the
setting to not allow the selection of days on weekends.
$(selector).datepick({
onDate: $.datepick.noWeekends});
$.datepick.changeFirstDay-
Attach this function to the
setting to allow the first day of the week to be changed
by clicking on the day column headers.
$(selector).datepick({
onShow: $.datepick.changeFirstDay});
Since 4.0.0 - previously
it was the changeFirstDay setting.
$.datepick.hoverCallback(onHover)-
Attach this function to the
setting to provide a callback when hovering over a day.
onHover (function) is the callback function that receives the
current date (Date) and a flag (boolean)
indicating selectability as parameters on entry, and no parameters on exit,
while this refers to the target input or division/span.
$(selector).datepick({
onShow: $.datepick.hoverCallback(showHover)});
function showHover(date, selectable) {
$('#hoverOutput').text(
(selectable ? $.datepick.formatDate(date) : null) || 'nothing');
Since 4.0.0 - previously
it was the onHover setting.
$.datepick.highlightWeek-
Attach this function to the
setting to highlight the entire week when hovering over a day.
$(selector).datepick({
onShow: $.datepick.highlightWeek});
Since 4.0.0 - previously
it was the highlightWeek setting.
$.datepick.monthOnly-
Attach this function to the
setting to only allow selection of a month as a whole.
The date returned is the first day of the chosen month.
$(selector).datepick({
onShow: $.datepick.monthOnly});
Since 4.0.0.
$.datepick.showStatus-
Attach this function to the
setting to show a status bar beneath the month(s)
and to redirect tooltip information to that area.
$(selector).datepick({
onShow: $.datepick.showStatus});
Since 4.0.0 - previously
it was the showStatus setting.
Attach this function to the
setting to include links for each month and surrounding years
above the month header to simplify navigation between months/years.
$(selector).datepick({changeMonth: false,
onShow: $.datepick.monthNavigation});
Since 4.0.2.
$.datepick.selectWeek-
Attach this function to the
setting to select the entire week when the associated
week of the year entry is selected. You must use the
for this to work,
and the datepicker should be set as a
$(selector).datepick({rangeSelect: true,
renderer: $.datepick.weekOfYearRenderer,
onShow: $.datepick.selectWeek});
Since 4.0.0.
$.datepick.selectMonth-
Attach this function to the
setting to select the entire month when the
week of the year column header is selected. You must use the
for this to work,
and the datepicker should be set as a
$(selector).datepick({rangeSelect: true,
renderer: $.datepick.weekOfYearRenderer,
onShow: $.datepick.selectMonth});
Since 4.0.0.
The datepicker can be integrated with J?rn Zaefferer's
adding the jquery.datepick.validation.js extension to your page.
Since 3.5.1.
Since 4.0.5 - combined validation rules into dpDate;
previously there were also dpMinDate, dpMaxDate,
and dpMinMaxDate, added dpCompareDate rule.
One new validation is defined (dpDate). It automatically handles date ranges
(including checking that the start date is not after the end date) and multiple dates,
checks against any minDate and/or maxDate settings,
and calls any onDate callback to verify selectability.
It may be added as a class to your datepicker fields, or may
be defined in the validate settings.
A second validation rule (dpCompareDate) lets you compare one date
field with another date. This rule must be specified in the rules
section of the validate call and be provided with a parameter to
indicate the required comparison and the target date. Specify the comparison
with any of the following: 'equal', 'eq', 'same', 'notEqual', 'ne', 'notSame',
'lessThan', 'lt', 'before', 'greaterThan', 'gt', 'after', 'notLessThan', 'ge',
'notBefore', 'notGreaterThan', 'le', 'notAfter'. Specify the target date as either
the actual date (as a string in the current date format or a Date
object), as 'today', or as another datepicker field (as a jQuery selector,
jQuery collection, or DOM element). The two parameters can be combined into one
string (if the latter is a string), be given as items in an array, or be given
as an object with a single attribute named for the comparison and with a value
of the target.
$('form').validate({
dpCompareDate: 'before 12/25/2014'
dpCompareDate: ['ne', new Date(2014, 12 - 1, 25)]
dpCompareDate: {notLessThan: '#otherField'}
There is also a custom errorPlacement function defined so that
the error messages appear after any trigger button or icon
(or before it if using a right-to-left localisation).
You can customise the error messages via the datepicker defaults:
$.datepick.({...}).
The message fields are validateDate, validateDateMin,
validateDateMax, validateDateMinMax,
validateDateCompare, validateDateToday, validateDateOther,
validateDateEQ, validateDateNE, validateDateLT,
validateDateGT, validateDateLE, and validateDateGE.
Within these messages '{n}' mark substitution points.
The sample page below show how the validations would be used.
It defines three datepicker fields: one plain, one a date range, and
one with a maximum limit. The validations are applied to the first and
last by including the dpDate class on the fields.
For the middle one the validation is defined in the validate
call on the form, along with a required setting.
Also note that a custom message is defined for the date range field.
&link type="text/css" rel="stylesheet" href="css/jquery.datepick.css"&
&script type="text/javascript" src="js/jquery-1.8.3.js"&&/script&
&script type="text/javascript" src="js/jquery.validate.js"&&/script&
&script type="text/javascript" src="js/jquery.datepick.js"&&/script&
&script type="text/javascript" src="js/jquery.datepick.validation.js"&&/script&
&script type="text/javascript"&
$(function() {
$('#favDate').datepick();
$('#holidayDates').datepick({rangeSelect: true});
$('#birthDate').datepick({maxDate: 0});
$('#validateForm').validate({
errorPlacement: $.datepick.errorPlacement,
holidayDates: {
required: true,
dpDate: true
messages: {
holidayDates: 'Please enter a valid date range'
&form id="validateForm"&
&p&Favourite date: &input type="text" id="favDate"
name="favDate" size="10" class="dpDate"/&&/p&
&p&Period of last holiday: &input type="text" id="holidayDates"
name="holidayDates" size="24"/&&/p&
&p&Date of birth: &input type="text" id="birthDate"
name="birthDate" size="10" class="dpDate"/&&/p&
Compatibility
Version 4.0.0 is a major update to the datepicker.
As such, several compatibility issues arise when upgrading from version
dateFormat years have changed: use 'yy' for two digit year
or 'yyyy' for four digit year.
showOn, buttonText, buttonImage, and
buttonImageOnly settings are replaced by
showOnFocus and showTrigger settings.
$(selector).datepick({showOn: 'button'});
$(selector).datepick({showOnFocus: false, showTrigger: '&button>...&/button>'});
$(selector).datepick({showOn: 'both', buttonImage: 'img/mycal.gif', buttonImageOnly: true});
$(selector).datepick({showTrigger: '&img src="img/mycal.gif" alt="...">&/img>'});
duration setting is replaced by the showSpeed setting.
numberOfMonths setting is replaced by the monthsToShow
setting and showCurrentAtPos setting is replaced by the
monthsOffset setting.
stepMonths setting is replaced by the monthsToStep
setting and stepBigMonths setting is replaced by the
monthsToJump setting.
changeYear setting is no longer available while the
changeMonth setting now controls both drop-downs.
showDefault setting is replaced by the
selectDefaultDate setting.
closeAtTop, gotoCurrent, mandatory,
showBigPrevNext, and showMonthAfterYear
settings are no longer available but the same
functionality can be achieved with the renderer setting.
hideIfNoPrevNext setting is no longer available
but the same functionality can be achieved with the pickerClass
setting and some CSS.
navigationAsDateFormat setting is replaced by the
commandsAsDateFormat setting.
onClose and onSelect functions only receive an
array of Date objects as a parameter.
appendText setting is no longer available but the same
functionality can be achieved using normal jQuery.
useThemeRoller setting is no longer available
but the same functionality can be achieved with the renderer
setting and the themeRollerRenderer object in the extension module.
$(selector).datepick({useThemeRoller: true});
$(selector).datepick({renderer: $.datepick.themeRollerRenderer});
beforeShowDay setting is replaced by onDate setting
and returns an object with attributes instead of an array.
$(selector).datepick({beforeShowDay: highlightDays});
function highlightDays(date) {
return [true, 'highlight', 'tooltip'];
$(selector).datepick({onDate: highlightDays});
function highlightDays(date) {
return {selectable: true, dateClass: 'highlight', title: 'tooltip'};
beforeShow setting is no longer available but similar functionality
can be achieved by using the option command at an earlier time.
changeFirstDay setting is no longer available but the same
functionality can be achieved with the onShow setting
and the changeFirstDay function in the extension module.
$(selector).datepick({changeFirstDay: true});
$(selector).datepick({onShow: $.datepick.changeFirstDay});
showWeeks setting is no longer available but the same
functionality can be achieved with the renderer setting
and the weekOfYearRenderer object in the extension module.
$(selector).datepick({showWeeks: true});
$(selector).datepick({renderer: $.datepick.weekOfYearRenderer});
highlightWeek setting is no longer available but the same
functionality can be achieved with the onShow setting
and the highlightWeek function in the extension module.
$(selector).datepick({highlightWeek: true});
$(selector).datepick({onShow: $.datepick.highlightWeek});
onHover setting is no longer available but the same
functionality can be achieved with the onShow setting
and the hoverCallback function in the extension module.
$(selector).datepick({onHover: hoveringOver});
$(selector).datepick({onShow: $.datepick.hoverCallback(hoveringOver)});
showStatus setting is no longer available but the same
functionality can be achieved with the onShow setting
and the showStatus function in the extension module.
$(selector).datepick({showStatus: true});
$(selector).datepick({onShow: $.datepick.showStatus});
Opening the datepicker in a dialog is no longer available but the same
functionality can be achieved by combining the datepicker with the
at wood.keith{.au
with comments or suggestions.
& 2009-15, Keith Wood

我要回帖

更多关于 js img.complete 的文章

 

随机推荐