bootstrap datepicker限定可選時(shí)間范圍實(shí)現(xiàn)方法
一、應(yīng)用場(chǎng)景
實(shí)際應(yīng)用中可能會(huì)根據(jù)日期字段查詢某個(gè)日期范圍內(nèi)的數(shù)據(jù),則需要對(duì)日期選擇器可選時(shí)間進(jìn)行限制,
如:開(kāi)始時(shí)間不能大于結(jié)束時(shí)間,結(jié)束時(shí)間不能小于開(kāi)始時(shí)間,此時(shí)就要為開(kāi)始日期選擇器和結(jié)束日期選擇器動(dòng)態(tài)的設(shè)置startDate和endDate的值。
二、相關(guān)知識(shí)點(diǎn)
1、bootstrap-datepicker的初始化
引入bootstrap-datepicker.js和bootstrap-datepicker.css
bootstrap-datepicker配置參數(shù)的了解
2、boostrap-datepicker的changeDate事件:日期改變時(shí)觸發(fā)
3、bootstrap-datepicker的setEndDate和setStartDate方法
4、詳細(xì)配置參見(jiàn)官方文檔 http://bootstrap-datepicker.readthedocs.org/en/latest/methods.html
三、應(yīng)用實(shí)例
1、JSP中,聲明日期選擇器
<span style="font-size:14px;"><div class="col-md-6 cy-text-right-md"> <div class="form-inline"> <div class="form-group cy-mar-ver-s"> <span class="cy-pad-hor-s">最后接入時(shí)間</span> </div> <div class="input-daterange input-group" id="datepicker"> <input type="text" class="form-control" name="start" id="qBeginTime" /> <span class="input-group-addon">至</span> <input type="text" class="form-control" name="end" id="qEndTime" /> </div> <div class="form-group cy-mar-ver-s"> <button class="btn btn-primary cy-pad-rgt-s" onclick="javascript:doQuery();" type="button">搜索</button> </div> </div> </div></span>
2、JS中,對(duì)日期選擇器進(jìn)行初始化和配置
<span style="font-size:14px;"> //開(kāi)始時(shí)間:
$('#qBeginTime').datepicker({
todayBtn : "linked",
autoclose : true,
todayHighlight : true,
endDate : new Date()
}).on('changeDate',function(e){
var startTime = e.date;
$('#qEndTime').datepicker('setStartDate',startTime);
});
//結(jié)束時(shí)間:
$('#qEndTime').datepicker({
todayBtn : "linked",
autoclose : true,
todayHighlight : true,
endDate : new Date()
}).on('changeDate',function(e){
var endTime = e.date;
$('#qBeginTime').datepicker('setEndDate',endTime);
});</span>
3、效果圖


以上所述是小編給大家介紹的bootstrap datepicker限定可選時(shí)間范圍實(shí)現(xiàn)方法,希望對(duì)大家有所幫助,如果大家有任何疑問(wèn)請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!
- bootstrap datepicker的基本使用教程
- JS控件bootstrap datepicker使用方法詳解
- BootStrap Datepicker 插件修改為默認(rèn)中文的實(shí)現(xiàn)方法
- 淺談Bootstrap的DatePicker日期范圍選擇
- bootstrap datepicker 與bootstrapValidator同時(shí)使用時(shí)選擇日期后無(wú)法正常觸發(fā)校驗(yàn)的解決思路
- BootStrap中Datepicker控件帶中文的js文件
- BootStrap的Datepicker控件使用心得分享
- bootstrap 日期控件 datepicker被彈出框dialog覆蓋的解決辦法
相關(guān)文章
原生JS實(shí)現(xiàn)左右箭頭選擇日期實(shí)例代碼
原生JS 左右箭頭選擇日期,就是用左右尖括號(hào)可改變中間日期的值,代碼簡(jiǎn)單易懂,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友參考下2017-03-03
微信小程序數(shù)據(jù)分析之自定義分析的實(shí)現(xiàn)
這篇文章主要介紹了微信小程序數(shù)據(jù)分析之自定義分析的實(shí)現(xiàn),小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2018-08-08
JavaScript中各種編碼解碼函數(shù)的區(qū)別和注意事項(xiàng)
JavaScript 中encodeURI,encodeURIComponent與escape的區(qū)別和注2010-08-08
JavaScript 編寫(xiě)匿名函數(shù)的幾種方法
匿名函數(shù)可以有效控制變量作用域,構(gòu)造閉包 (Closure),防止對(duì)全局變量造成污染。在 JavaScript 中,編寫(xiě)匿名函數(shù),有以下幾種方法.2010-02-02
javascript對(duì)JSON數(shù)據(jù)排序的3個(gè)例子
這篇文章主要介紹了javascript對(duì)JSON數(shù)據(jù)排序的3個(gè)例子的相關(guān)資料2014-04-04
JavaScript實(shí)現(xiàn)電話號(hào)碼格式化的解法小結(jié)
在 JavaScript 編程中,經(jīng)常會(huì)遇到將給定數(shù)據(jù)轉(zhuǎn)換為特定格式的問(wèn)題,本文為大家整理了一些常用方法,感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下2024-11-11
js倒計(jì)時(shí)簡(jiǎn)單實(shí)現(xiàn)代碼
這篇文章主要為大家詳細(xì)介紹了js倒計(jì)時(shí)簡(jiǎn)單實(shí)現(xiàn)代碼,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-08-08

