地址:http://jqueryui.com/datepicker/

使用:$( "#datepicker" ).datepicker();

$.datepicker.setDefaults( settings ) - 全局设置日期选择插件的参数.
$.datepicker.formatDate( format, date, settings ) - 格式化显示的日期字符串
$.datepicker.iso8601Week( date ) - 给出一个日期,确实他是一年中的第几周
$.datepicker.parseDate( format, value, settings ) - 按照指定格式获取日期字符串 changeYear和changeMonth为true时可以下拉框选择年份和月份。
设置格式:
The format for parsed and displayed dates. For a full list of the possible formats see the formatDate function.

Code examples:

Initialize the datepicker with the dateFormat option specified:

1
2
3
$( ".selector" ).datepicker({
dateFormat: "yy-mm-dd"
});

Get or set the dateFormat option, after initialization:

1
2
3
4
5
// Getter
var dateFormat = $( ".selector" ).datepicker( "option", "dateFormat" );
 
// Setter
$( ".selector" ).datepicker( "option", "dateFormat", "yy-mm-dd" );
重要方法:

beforeShowType: FunctionElement input, Object inst )

Default: null
A function that takes an input field and current datepicker instance and returns an options object to update the datepicker with. It is called just before the datepicker is displayed.
 

onChangeMonthYearType: FunctionInteger year, Integer month, Object inst )

Default: null
Called when the datepicker moves to a new month and/or year. The function receives the selected year, month (1-12), and the datepicker instance as parameters. this refers to the associated input field.
 
this同beforeShow的input一样。

datepicker的中文汉化设置:
jQuery(function($){
$.datepicker.regional['zh-CN'] = {
closeText: '关闭',
prevText: '<上月',
nextText: '下月>',
currentText: '今天',
monthNames: ['1月','2月','3月','4月','5月','6月',
'7月','8月','9月','10月','11月','12月'],
monthNamesShort: ['1月','2月','3月','4月','5月','6月',
'7月','8月','9月','10月','11月','12月'],
dayNames: ['星期日','星期一','星期二','星期三','星期四','星期五','星期六'],
dayNamesShort: ['周日','周一','周二','周三','周四','周五','周六'],
dayNamesMin: ['日','一','二','三','四','五','六'],
weekHeader: '周',
dateFormat: 'yy-mm-dd',
firstDay: 1,
isRTL: false,
showMonthAfterYear: true,
yearSuffix: '年', changeYear:true,
changeMonth:true,
showButtonPanel: true,
minDate:'2013-01-01',
};
$.datepicker.setDefaults($.datepicker.regional['zh-CN']);
});

问题:

jquery-ui datepicker的z-index 太小被覆盖

如何置jquery-ui datepicker的z-index值的呢?

分析datepicker的源码,发现弹出的日期选择框的z-index值是:$(input).zIndex() + 1。继续分析$.zIndex()函数(在jquery-ui.js文件中),发现当input的css position值为absolute、fixed或relative时,$.zIndex()函数返回的值就是input css 的z-index值。

例如:<input type="text" name="add_date" id="add_date" style="z-index:1000;position:relative;" value="" />这样设置时,弹出的jquery-ui datepicker日期选择框的z-index值就设置为1001了。

不想设置input,有没有其他办法呢?

一种看似投机的办法:

beforeShow: function () { 
setTimeout( 
function () { 
 $('#ui-datepicker-div').css("z-index", 15); 
 }, 10 
);

参考:http://bugs.jqueryui.com/ticket/5479#comment:4

在buttonPanel增加自定义button:

 $('#control-date').datepicker({
beforeShow: function(input, ui) {
setTimeout(function() {
var buttonPane = $( input ).datepicker( "widget" ).find( ".ui-datepicker-buttonpane" );
var button1 = $( "<button>", {
text: "今天",
click: function() {
var today = new Date();
$( input ).datepicker( "setDate", today);
setTimeout(function(){
$( input ).datepicker( 'hide');
},10);
}
});
var button2 = $( "<button>", {
text: "明天",
click: function() {
$( input ).datepicker( "setDate", '+1d');
setTimeout(function(){
$( input ).datepicker( 'hide');
},10);
}
});
var button3 = $( "<button>", {
text: "本周五",
click: function() {
var today=new Date();
var weekday=today.getDay();
var friday=new Date(1000*60*60*24*(5-weekday) + today.getTime());
$( input ).datepicker( "setDate", friday);
setTimeout(function(){
$( input ).datepicker( 'hide');
},10);
}
});
var button4 = $( "<button>", {
text: "清空",
click: function() {
$.datepicker._clearDate( input );
}
});
if( buttonPane ) {
buttonPane.html('');
button1.appendTo( buttonPane ).addClass("ui-datepicker-current ui-state-default ui-priority-primary ui-corner-all ui-datepicker-button");
button2.appendTo( buttonPane ).addClass("ui-datepicker-current ui-state-default ui-priority-primary ui-corner-all ui-datepicker-button");
button3.appendTo( buttonPane ).addClass("ui-datepicker-current ui-state-default ui-priority-primary ui-corner-all ui-datepicker-button");
button4.appendTo( buttonPane ).addClass("ui-state-default ui-priority-primary ui-corner-all ui-datepicker-button");
}
},1); //end setTimeout
},
showButtonPanel: true,
});
 参考:http://ifxoxo.com/jquery-datepicker-add-button.html
在stackoverflow上的http://stackoverflow.com/questions/4598850/how-do-you-add-buttons-to-a-jquery-datepicker-in-the-button-panel 回答也跟上面一样。

jquery datepicker日历控件的更多相关文章

  1. jquery插件——日历控件

    今天在网上有看到一个jquery插件——日历控件,不过之前也在柯乐义的网站上看到了(http://keleyi.com/ 推荐下) 这个插件看着比较大气,所以干脆也分享下,以后自己也好用一点儿 1.页 ...

  2. amazeui datepicker日历控件 设置默认当日

    amazeui datepicker日历控件 设置默认当日 背景: 最近在做一个系统的时候,前台需要选择日期,传给后台进行处理,每次都需要通过手动点击组件,选择日期,这样子很不好,所以我想通过程序自动 ...

  3. 如何使用jqueryUi的datepicker日历控件?

    参考: http://www.jb51.net/article/85007.htm 这里的日历控件是, 基于jquery的jqureyui中的一个 widget. 需要js 文件: 外部的js文件, ...

  4. jQuery Datepicker日期控件

    datepicker可以为bootstrap添加一个事件选择控件,适用于任何需要调用的场合,支持多种事件格式输出(比如:dd, d, mm, m, yyyy, yy等),是制作网页不可缺失的插件. R ...

  5. JQuery datepicker 日期控件设置

    datepicker控件可通过参数设置进行语言切换,以下可实现,系统所有日期控件默认为中文,在特定页面或者特定条件下可切换成英语!~ HTML: <!DOCTYPE html> <h ...

  6. 【前端控件】JQuery datepicker 日期控件设置

    datepicker控件可通过参数设置进行语言切换,以下可实现,系统所有日期控件默认为中文,在特定页面或者特定条件下可切换成英语!~ HTML: <!DOCTYPE html> <h ...

  7. jquery M97-datepicker日历控件

    My97DatePicker是一款非常灵活好用的日期控件.使用非常简单. 1.下载My97DatePicker组件包 2.在页面中引入该组件js文件:     <script type=&quo ...

  8. jquery datepicker日期控件用法

    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.c ...

  9. jquery easyui 日历控件和文本框结合使用生成日期

    html部分---等待接收所选日期的文本框 <td> <input name='input_date' required class='easyui-textbox' id='xiw ...

随机推荐

  1. 142. Linked List Cycle II【easy】

    142. Linked List Cycle II[easy] Given a linked list, return the node where the cycle begins. If ther ...

  2. cp实现无提示覆盖拷贝

    在我们使用cp批量拷贝时,即使使用cp -rf ,遇到需要覆盖时,也是需要确认是否覆盖的. 解决办法1: 我们使用alias看一下别名设置会发现这样一行 alias cp='cp -i' 意思就是使用 ...

  3. js中级四: 跨域

    原文链接:http://www.cnblogs.com/scottckt/archive/2011/11/12/2246531.html 什么是跨域? 首先什么是跨域,简单地理解就是因为JavaScr ...

  4. jquery中Uncaught TypeError: $(...).ajaxUpload is not a function(…)错误解决方法

    错误原因:该函数不是jquery的核心函数,所以需要外部引入ajaxfileupload.js文件,可能是没有引入,或者引入的js文件互相冲突 解决方法:每次进入一个函数之前打印该函数所有的js文件, ...

  5. linux $* 和$@ if [ ](字符串比较)

    $* 将命令后面的参数理解为一个类似为字符串,$@理解为多个单个的参数,类似理解成数据 $#参数总数 [root@mini0 test]# ./test4.sh jskd sj21 Using the ...

  6. Keil(MDK-ARM)使用教程(一)_界面+菜单

    Ⅰ.概述 今天总结Keil(MDK-ARM)界面和菜单相关的内容,详情请往下看. 关于Keil的下载.安装和新建工程我已将在前面做了详细的总结,不懂的可以参考我博客里面相关的文章.该文章是在新建好工程 ...

  7. Cmder 配置使用

    官网下载 配置: 1.把 Cmder 加到环境变量 将Cmder.exe存放的目录添加到系统环境变量path 添加成功后,Win+r 输入cmder,可以正确打开cmder 窗口即可. 2.添加 cm ...

  8. Java进阶03 IO基础(转载)

    IO示例 下面是演示的文件file.txt Hello World! Hello Nerd! 先来研究一个文件读取的例子: import java.io.*;public class Test{ pu ...

  9. servelet 连接mysql

    package helloworld; import java.io.IOException; import java.io.PrintWriter; import java.sql.*; impor ...

  10. 第一百六十四节,jQuery,常规选择器

    jQuery,常规选择器 学习要点: 1.简单选择器 2.进阶选择器 3.高级选择器 jQuery 最核心的组成部分就是:选择器引擎.它继承了 CSS 的语法,可以对 DOM 元 素的标签名.属性名. ...