jQuery插件datepicker 日期連續(xù)選擇
先上效果:
代碼:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>日期選擇</title> <link rel="stylesheet" href="reset-jquery-ui.min.css" /> <script type="text/javascript" src="jquery-1.8.3.min.js"></script> <script type="text/javascript" src="jquery-ui.js"></script> <script type="text/javascript"> //日期選擇 $.datepicker.regional['zh-CN'] = { clearText: '清除', clearStatus: '清除已選日期', closeText: '關(guān)閉', closeStatus: '不改變當(dāng)前選擇', prevText: '<上月', prevStatus: '顯示上月', prevBigText: '<<', prevBigStatus: '顯示上一年', nextText: '下月>', nextStatus: '顯示下月', nextBigText: '>>', nextBigStatus: '顯示下一年', currentText: '今天', currentStatus: '顯示本月', monthNames: ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月'], monthNamesShort: ['一', '二', '三', '四', '五', '六', '七', '八', '九', '十', '十一', '十二'], monthStatus: '選擇月份', yearStatus: '選擇年份', weekHeader: '周', weekStatus: '年內(nèi)周次', dayNames: ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'], dayNamesShort: ['周日', '周一', '周二', '周三', '周四', '周五', '周六'], dayNamesMin: ['日', '一', '二', '三', '四', '五', '六'], dayStatus: '設(shè)置 DD 為一周起始', dateStatus: '選擇 m月 d日, DD', dateFormat: 'yy-mm-dd', firstDay: 1, initStatus: '請(qǐng)選擇日期', isRTL: false }; $.datepicker.setDefaults($.datepicker.regional['zh-CN']); var a = 0; var tmpdate = ""; /** * 實(shí)例化日期控件,并綁定回調(diào)函數(shù),傳入相應(yīng)參數(shù) * tagId 日期控件實(shí)例化的標(biāo)簽id * ajaxMethod 回調(diào)函數(shù) * ajaxMethod 函數(shù)需要用到的額外參數(shù) **/ function datePickerById(tagId){ $(tagId).datepicker( { isDataChecked:true, autoClose:true, showOtherMonths: true, changeYear: true, //showStatus: true, //showOn: "both", numberOfMonths:2,//顯示幾個(gè)月 showMonthAfterYear:true, onSelect: function(dateText,inst) {//選擇日期后執(zhí)行的操作 a++; inst.autoClose = true; if(a==1){ inst.settings.isDataChecked = false; tmpdate = dateText; } if(a==2){ a=0; inst.settings.isDataChecked = false; inst.autoClose = false; var date1 = new Date(tmpdate).getTime(); var date2 = new Date(dateText).getTime(); var arg = {time_s:date1,time_e:date2}; //ajax函數(shù)要用到的時(shí)間參數(shù) if(date1<date2){ $(tagId).val(tmpdate.replace(/-/ig,"-")+"至"+dateText.replace(/-/ig,"-")); }else if(date1 == date2){ a = 1; inst.settings.isDataChecked = false; inst.autoClose = true; }else{ $(tagId).val(dateText.replace(/-/ig,"-")+"至"+tmpdate.replace(/-/ig,"-")); } } } }); } </script> </head> <body> 時(shí)間選擇:<input id="div1" style="height:30px;width:190px;"/> <script type="text/javascript"> datePickerById('#div1'); </script> </body> </html>
基于jquery UI 1.11.4修改如下(在源碼里面修改):
/* Hide the date picker from view. * @param input element - the input field attached to the date picker */ _hideDatepicker: function(input) { var showAnim, duration, postProcess, onClose, inst = this._curInst; if (!inst || (input && inst !== $.data(input, "datepicker"))) { return; } /** * 2015.6.11 修改 * author:link * 增加inst.autoClose控制日歷面板 */ // ----------------------------------------------------------------------------------------- if (this._datepickerShowing||!inst.autoClose) { showAnim = this._get(inst, "showAnim"); duration = this._get(inst, "duration"); postProcess = function() { $.datepicker._tidyDialog(inst); }; // DEPRECATED: after BC for 1.8.x $.effects[ showAnim ] is not needed if(inst.autoClose===true){ // 這里不隱藏 }else{ if ( $.effects && ( $.effects.effect[ showAnim ] || $.effects[ showAnim ] ) ) { inst.dpDiv.hide(showAnim, $.datepicker._get(inst, "showOptions"), duration, postProcess); } else { inst.dpDiv[(showAnim === "slideDown" ? "slideUp" : (showAnim === "fadeIn" ? "fadeOut" : "hide"))]((showAnim ? duration : null), postProcess); } } // ----------------------------------------------------------------------------------------- if (!showAnim) { postProcess(); } this._datepickerShowing = false; onClose = this._get(inst, "onClose"); if (onClose) { onClose.apply((inst.input ? inst.input[0] : null), [(inst.input ? inst.input.val() : ""), inst]); } this._lastInput = null; if (this._inDialog) { this._dialogInput.css({ position: "absolute", left: "0", top: "-100px" }); if ($.blockUI) { $.unblockUI(); $("body").append(this.dpDiv); } } this._inDialog = false; } },
以上所述就是本文的全部?jī)?nèi)容了,希望大家能夠喜歡。
- jquery做個(gè)日期選擇適用于手機(jī)端示例
- jQuery移動(dòng)端日期(datedropper)和時(shí)間(timedropper)選擇器附源碼下載
- 基于jQuery滑動(dòng)桿實(shí)現(xiàn)購(gòu)買日期選擇效果
- 貼近用戶體驗(yàn)的Jquery日期、時(shí)間選擇插件
- Jquery日期選擇datepicker插件用法實(shí)例分析
- JQuery EasyUI 日期控件如何控制日期選擇區(qū)間
- jQuery之日期選擇器的深入解析
- 基于jQuery的日期選擇控件
- datePicker——日期選擇控件(with jquery)
- jquery仿蘋果的時(shí)間/日期選擇效果
相關(guān)文章
JavaScript使用readAsDataURL讀取圖像文件
這篇文章主要為大家詳細(xì)介紹了JavaScript使用readAsDataURL讀取圖像文件的方法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-05-05iframe里使用JavaScript控制主頁(yè)轉(zhuǎn)向的方法
這篇文章主要介紹了iframe里使用JavaScript控制主頁(yè)轉(zhuǎn)向的方法,涉及使用javascript實(shí)現(xiàn)iframe頁(yè)面跳轉(zhuǎn)的技巧,需要的朋友可以參考下2015-04-04

Kindeditor單獨(dú)調(diào)用多圖上傳實(shí)例

javascript cookie操作類的實(shí)現(xiàn)代碼小結(jié)附使用方法

BootStrap Validator 根據(jù)條件在JS中添加或移除校驗(yàn)操作

一文總結(jié)JavaScript中常見(jiàn)的設(shè)計(jì)模式