下載jQuery核心文件就不用說了吧,datepicker是輕量級插件,只需jQuery的min版本就行了,然后到官網(wǎng)下載jquery-ui壓縮包(可以選擇喜歡的theme),里面就包含對datepicker的支持,當然您也可以官網(wǎng)下載datepicker,包括ui.core.js和ui.datepicker.js。
推薦課程:jQuery教程。
jquery.ui.datepicker-zh-CN.js,內(nèi)容如下:
jQuery(function($){ $.datepicker.regional['zh-CN'] = { closeText: '關(guān)閉', prevText: '<上月', nextText: '下月>', currentText: '今天', monthNames: ['一月','二月','三月','四月','五月','六月', '七月','八月','九月','十月','十一月','十二月'], monthNamesShort: ['一','二','三','四','五','六', '七','八','九','十','十一','十二'], dayNames: ['星期日','星期一','星期二','星期三','星期四','星期五','星期六'], dayNamesShort: ['周日','周一','周二','周三','周四','周五','周六'], dayNamesMin: ['日','一','二','三','四','五','六'], weekHeader: '周', dateFormat: 'yy-mm-dd', firstDay: 1, isRTL: false, showMonthAfterYear: true, yearSuffix: '年'}; $.datepicker.setDefaults($.datepicker.regional['zh-CN']); });
實例:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML> <HEAD> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <TITLE>日期控件datepicker</TITLE> <!-- 引入 jQuery --> <mce:script src="js/jquery.1.4.2.js" mce_src="js/jquery.1.4.2.js" type="text/javascript"></mce:script> <!--添加datepicker支持--> <mce:script src="js/jquery.ui.core.js" mce_src="js/jquery.ui.core.js" type="text/javascript"></mce:script> <mce:script src="js/jquery.ui.datepicker.js" mce_src="js/jquery.ui.datepicker.js" type="text/javascript"></mce:script> <!-- 或者引入jquery ui包,其中也包含對datepicker的支持 <mce:script src="js/jquery-ui-1.7.3.custom.min.js" mce_src="js/jquery-ui-1.7.3.custom.min.js" type="text/javascript"></mce:script> --> <!--引入樣式css--> <link type="text/css" rel="stylesheet" href="css/jquery-ui-1.7.3.custom.css" mce_href="css/jquery-ui-1.7.3.custom.css" /> <!-- 添加中文支持--> <mce:script src="js/jquery.ui.datepicker-zh-CN.js" mce_src="js/jquery.ui.datepicker-zh-CN.js" type="text/javascript"></mce:script> <mce:script type="text/javascript"><!-- //等待dom元素加載完畢. $(function(){ $("#selectDate").datepicker({//添加日期選擇功能 numberOfMonths:1,//顯示幾個月 showButtonPanel:true,//是否顯示按鈕面板 dateFormat: 'yy-mm-dd',//日期格式 clearText:"清除",//清除日期的按鈕名稱 closeText:"關(guān)閉",//關(guān)閉選擇框的按鈕名稱 yearSuffix: '年', //年的后綴 showMonthAfterYear:true,//是否把月放在年的后面 defaultDate:'2011-03-10',//默認日期 minDate:'2011-03-05',//最小日期 maxDate:'2011-03-20',//最大日期 //monthNames: ['一月','二月','三月','四月','五月','六月','七月','八月','九月','十月','十一月','十二月'], //dayNames: ['星期日','星期一','星期二','星期三','星期四','星期五','星期六'], //dayNamesShort: ['周日','周一','周二','周三','周四','周五','周六'], //dayNamesMin: ['日','一','二','三','四','五','六'], onSelect: function(selectedDate) {//選擇日期后執(zhí)行的操作 alert(selectedDate); } }); }); // --></mce:script> </HEAD> <BODY> <input type="text" id="selectDate" readonly="readonly"/> </BODY> </HTML>
注意:由于jquery datepicker不是最新版本的,如果下載新版本jquery-ui-1.8.13中的css文件會造成日期控件不能顯示的問題,所以這里使用了1.7.3的ui。簡單一點就是用jquery-ui的壓縮js。
聲明:本網(wǎng)頁內(nèi)容旨在傳播知識,若有侵權(quán)等問題請及時與本網(wǎng)聯(lián)系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com