bootstrap日期控件問題(雙日期、清空等問題解決)

bootstrap以它優(yōu)美的外觀和豐富的組件,使它成為目前最流行的前端框架。在項(xiàng)目開發(fā)中,我們使用它的日期控件確實(shí)遇到了一些問題:

創(chuàng)新互聯(lián)建站-專業(yè)網(wǎng)站定制、快速模板網(wǎng)站建設(shè)、高性價比青原網(wǎng)站開發(fā)、企業(yè)建站全套包干低至880元,成熟完善的模板庫,直接使用。一站式青原網(wǎng)站制作公司更省心,省錢,快速模板網(wǎng)站建設(shè)找我們,業(yè)務(wù)覆蓋青原地區(qū)。費(fèi)用合理售后完善,10多年實(shí)體公司更值得信賴。

1.日期控件后面兩個圖標(biāo)點(diǎn)擊觸發(fā)失效

2.雙日期關(guān)聯(lián)問題

3.雙日期清空時,之前輸入日期關(guān)聯(lián)仍然有效

4.輸入年月

5.圖標(biāo)不顯示(這個直接在引入圖標(biāo)的文件里搜url地址,修改地址就可以解決)

下面的代碼都會一一解決。

<!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,否則后面兩個小圖標(biāo)會失效
  $("#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('');
  //用于解決清空后,前后日期還會關(guān)聯(lián)的問題
  $('.input-group-addon:has(span.glyphicon-remove)').click();
}
  </script>
</head>
<body>
  <h2>bootstrap日期控件</h2>
  <hr/>
                    <div id="startdiv" class="input-group date width200">
                      <input id="start"
                        name="start" class="form-control" type="text"
                        value="" placeholder="請輸入開始日期" 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 width200">
                      <input id="end"
                        name="end" class="form-control" type="text"
                        value="" placeholder="請輸入結(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 width200">
                      <input id="birthDay"
                        name="birthDay" class="form-control" type="text"
                        value="" placeholder="請輸入出生年月" 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日期控件問題(雙日期、清空等問題解決),希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復(fù)大家的。在此也非常感謝大家對創(chuàng)新互聯(lián)網(wǎng)站的支持!

網(wǎng)頁標(biāo)題:bootstrap日期控件問題(雙日期、清空等問題解決)
網(wǎng)站地址:http://bm7419.com/article34/igdise.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)頁設(shè)計(jì)公司、定制網(wǎng)站網(wǎng)站改版、網(wǎng)站排名、服務(wù)器托管、定制開發(fā)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

網(wǎng)站優(yōu)化排名