bootstrap日期控件問題(雙日期、清空等問題解決)
bootstrap以它優(yōu)美的外觀和豐富的組件,使它成為目前最流行的前端框架。在項(xiàng)目開發(fā)中,我們使用它的日期控件確實(shí)遇到了一些問題:
1.日期控件后面兩個(gè)圖標(biāo)點(diǎn)擊觸發(fā)失效
2.雙日期關(guān)聯(lián)問題
3.雙日期清空時(shí),之前輸入日期關(guān)聯(lián)仍然有效
4.輸入年月
5.圖標(biāo)不顯示(這個(gè)直接在引入圖標(biāo)的文件里搜url地址,修改地址就可以解決)
下面的代碼都會(huì)一一解決。
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="bootstrap.css" rel="external nofollow" type="text/css" />
<link rel="stylesheet" href="bootstrap-datetimepicker.css" rel="external nofollow" type="text/css" />
<script src="jquery-1.11.1.min.js" type="text/javascript"></script>
<script src="bootstrap.js" type="text/javascript" ></script>
<script src="bootstrap-datetimepicker.js" type="text/javascript" ></script>
<script src="bootstrap-datetimepicker.zh-CN.js" type="text/javascript" ></script>
<title>bootstrap日期</title>
<style>
</style>
<script type="text/javascript">
$(function(){
//輸入開始日期和結(jié)束日期
//定位div上的id,不是input上id,否則后面兩個(gè)小圖標(biāo)會(huì)失效
$("#startdiv").datetimepicker({
pickerPosition : "bottom-left",
language : 'zh-CN',
format : "yyyy-mm-dd",
weekStart : 1,
todayBtn : 1,
autoclose : 1,
todayHighlight : 1,
startView : 2,
minView : 2,
forceParse : 0
});
$("#endDiv").datetimepicker({
pickerPosition : "bottom-left",
language : 'zh-CN',
format : "yyyy-mm-dd",
weekStart : 1,
todayBtn : 1,
autoclose : 1,
todayHighlight : 1,
startView : 2,
minView : 2,
forceParse : 0
});
//輸入年月
$("#birthMonth").datetimepicker({
language: 'zh-CN',
format: 'yyyy-mm',
autoclose: true,
// todayBtn: true, 今天提示
startView: 'year',
minView:'year',
maxView:'decade'
});
$('#startdiv').unbind("change");
$('#startdiv').change(function(){
$('#endDiv').datetimepicker('setStartDate', $("#start").val());
});
$('#endDiv').unbind("change");
$('#endDiv').change(function(){
$('#startdiv').datetimepicker('setEndDate', $("#end").val());
});
});
function clearForm(){
$('#start').val('');
$('#end').val('');
//用于解決清空后,前后日期還會(huì)關(guān)聯(lián)的問題
$('.input-group-addon:has(span.glyphicon-remove)').click();
}
</script>
</head>
<body>
<h1>bootstrap日期控件</h1>
<hr/>
<div id="startdiv" class="input-group date width100">
<input id="start"
name="start" class="form-control" type="text"
value="" placeholder="請(qǐng)輸入開始日期" readonly="readonly"> <span
class="input-group-addon"> <span
class="glyphicon glyphicon-remove"></span>
</span> <span class="input-group-addon"> <span
class="glyphicon glyphicon-calendar"></span>
</span>
</div>
<br>
<div id="endDiv" class="input-group date width100">
<input id="end"
name="end" class="form-control" type="text"
value="" placeholder="請(qǐng)輸入結(jié)束日期" readonly="readonly"> <span
class="input-group-addon"> <span
class="glyphicon glyphicon-remove"></span>
</span> <span class="input-group-addon"> <span
class="glyphicon glyphicon-calendar"></span>
</span>
</div>
<br>
<button type="button" class="btn btn-sm btn-warning" id="clear" onclick="clearForm()">清空</button>
<hr>
<div id="birthMonth" class="input-group date width100">
<input id="birthDay"
name="birthDay" class="form-control" type="text"
value="" placeholder="請(qǐng)輸入出生年月" readonly="readonly"> <span
class="input-group-addon"> <span
class="glyphicon glyphicon-remove"></span>
</span> <span class="input-group-addon"> <span
class="glyphicon glyphicon-calendar"></span>
</span>
</div>
</body>
</html>
以上所述是小編給大家介紹的bootstrap日期控件問題(雙日期、清空等問題解決),希望對(duì)大家有所幫助,如果大家有任何疑問請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!
相關(guān)文章
值得分享的輕量級(jí)Bootstrap Table表格插件
這篇文章為大家分享了輕量級(jí)Bootstrap Table表格插件,以表格的形式顯示的數(shù)據(jù),支持單選,復(fù)選框,排序,分頁(yè),顯示/隱藏列等操作,感興趣的小伙伴們可以參考一下2016-05-05
使用BootStrap實(shí)現(xiàn)表格隔行變色及hover變色并在需要時(shí)出現(xiàn)滾動(dòng)條
這篇文章主要介紹了使用BootStrap實(shí)現(xiàn)表格隔行變色及hover變色并在需要時(shí)出現(xiàn)滾動(dòng)條效果,代碼簡(jiǎn)單易懂,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下2017-01-01
JavaScript面試中常考的字符串操作方法大全(包含ES6)
對(duì)于JavaScript字符串操作方法,你真的全部掌握了嗎?來看看這篇面試中??嫉淖址僮鞔笕?,包含最新的ES6字符串操作方法,值得收藏哦2020-05-05
Kendo Grid editing 自定義驗(yàn)證報(bào)錯(cuò)提示的解決方法
Kendo UI是一個(gè)強(qiáng)大的框架用于快速HTML5 UI開發(fā)。基于最新的HTML5、CSS3和JavaScript標(biāo)準(zhǔn)。今天小編通過分享本文給大家介紹Kendo Grid editing 自定義驗(yàn)證報(bào)錯(cuò)提示的解決方法2016-11-11
全面解析JavaScript中apply和call以及bind(推薦)
在javascript中apply、call和bind是三兄弟,很好的搭檔,下面小編給大家全面解析JavaScript中apply和call以及bind的相關(guān)知識(shí),感興趣的朋友一起學(xué)習(xí)吧2016-06-06
JavaScript?中?this?關(guān)鍵字的作用及改變其上下文的方法
這篇文章主要介紹了JavaScript?中?this?關(guān)鍵字的作用和如何改變其上下文,通過使用?call,?apply,?bind?方法,可以改變函數(shù)中的?this?指向,從而在不同的上下文中使用同一個(gè)函數(shù),需要的朋友可以參考下2023-01-01

