bootstrap日期控件問(wèn)題(雙日期、清空等問(wèn)題解決)
bootstrap以它優(yōu)美的外觀和豐富的組件,使它成為目前最流行的前端框架。在項(xiàng)目開發(fā)中,我們使用它的日期控件確實(shí)遇到了一些問(wèn)題:
1.日期控件后面兩個(gè)圖標(biāo)點(diǎn)擊觸發(fā)失效
2.雙日期關(guān)聯(lián)問(wè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)的問(wè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日期控件問(wèn)題(雙日期、清空等問(wèn)題解決),希望對(duì)大家有所幫助,如果大家有任何疑問(wèn)請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!
相關(guān)文章
js實(shí)現(xiàn)感應(yīng)鼠標(biāo)圖片透明度變化的方法
這篇文章主要介紹了js實(shí)現(xiàn)感應(yīng)鼠標(biāo)圖片透明度變化的方法,涉及javascript鼠標(biāo)操作及css修改技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-02-02
layui時(shí)間控件選擇時(shí)間范圍的實(shí)現(xiàn)方法
今天小編就為大家分享一篇layui時(shí)間控件選擇時(shí)間范圍的實(shí)現(xiàn)方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2019-09-09
在JavaScript 中按字母排序之如何在 JS 中按名稱排序
有時(shí)你可能有一個(gè)單詞數(shù)組,你想按字母順序(從 a-z)對(duì)每個(gè)單詞進(jìn)行排序,或者你可能有一個(gè)包含用戶信息(包括名字)的對(duì)象數(shù)組,例如,你想按照用戶的名字來(lái)排序,接下來(lái)通過(guò)本文給大家介紹在JavaScript 中按字母排序之如何在 JS 中按名稱排序,需要的朋友可以參考下2023-09-09
通過(guò)js給網(wǎng)頁(yè)加上水印背景實(shí)例
這篇文章主要介紹了通過(guò)js給網(wǎng)頁(yè)加上水印背景實(shí)例,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,,需要的朋友可以參考下2019-06-06
JavaScript Event學(xué)習(xí)第八章 事件的順序
在第一章中我提到一個(gè)初次看起來(lái)可能不是那么好理解的是一個(gè)問(wèn)題:“如果一個(gè)元素和他的父元素對(duì)于同樣的事件都有事件處理程序,那么哪個(gè)會(huì)首先執(zhí)行呢?”毫無(wú)疑問(wèn),看是什么瀏覽器。2010-02-02
js實(shí)現(xiàn)按座位號(hào)抽獎(jiǎng)
本文主要介紹了js實(shí)現(xiàn)按座位號(hào)抽獎(jiǎng)的示例代碼。具有很好的參考價(jià)值。下面跟著小編一起來(lái)看下吧2017-04-04
IE和Firefox的Javascript兼容性總結(jié)[推薦收藏]
長(zhǎng)久以來(lái)JavaScript兼容性一直是Web開發(fā)者的一個(gè)主要問(wèn)題。在正式規(guī)范、事實(shí)標(biāo)準(zhǔn)以及各種實(shí)現(xiàn)之間的存在的差異讓許多開發(fā)者日夜煎熬2011-10-10

