亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

日期選擇器上的 Jquery 日期禁用不起作用

日期選擇器上的 Jquery 日期禁用不起作用

PHP
catspeake 2021-11-19 16:23:51
我知道關于它的主題很多,但在解決這個問題幾天后我決定發布。我需要在我的引導日期選擇器中禁用日期,這里是 html 代碼:<head><!-- Required meta tags --><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"><!-- Bootstrap CSS --><link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous"><link href="https://fonts.googleapis.com/css?family=Noto+Sans" rel="stylesheet"><link rel="stylesheet" href="../Css/css.css"><link href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.1/themes/base/jquery-ui.css" rel="stylesheet" /><script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script><script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.1/jquery-ui.min.js"></script><input type="text"  class="form-control" id="txt_dateDebut" value="<?php     echo $uneLocation->getDateDebut(); ?>" name="txt_dateDebut" required>所以我在 Jquery 中嘗試了很多解決方案,但沒有任何反應,這是一個:    //disable these datesvar datesForDisable = ["25-01-2019", "26-01-2019", "27-01-2019"];$("#txt_dateDebut").datepicker({    format: 'dd/mm/yyyy',    autoclose: true,    weekStart: 1,    calendarWeeks: true,    todayHighlight: true,    beforeShowDay: function(date){        //format date in datepicker to dd-mm-yy        var date1 = $.datepicker.formatDate('dd-mm-yy', date);        //disable dates        return [ datesForDisable.indexOf(date1) == -1 ]    }});(一旦測試成功完成,目標是動態填充 PHP 的日期表以禁用)
查看完整描述

2 回答

?
qq_花開花謝_0

TA貢獻1835條經驗 獲得超7個贊

您可以使用datepicker 的 beforeShowDay來禁用日期。即:


//disable these dates

var datesForDisable = ["25.01.2019", "26.01.2019", "27.01.2019"]


$("#txt_dateDebut").datepicker({

      format: 'dd/mm/yyyy',

      autoclose: true,

      weekStart: 1,

      calendarWeeks: true,

      todayHighlight: true,

      beforeShowDay: function(date){

       //format date in datepicker to dd-mm-yy

        var date1 = $.datepicker.formatDate('dd.mm.yy', date);

        //disable dates

        return [ datesForDisable.indexOf(date1) == -1 ]

       }

      });

<link href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.1/themes/base/jquery-ui.css" rel="stylesheet" />

<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>

<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.1/jquery-ui.min.js"></script>


<input  type="text" class="form-control" id="txt_dateDebut" value="<?php echo $uneLocation->getDateDebut(); ?>" name="txt_dateDebut" required>


查看完整回答
反對 回復 2021-11-19
?
交互式愛情

TA貢獻1712條經驗 獲得超3個贊

如果您使用引導日期選擇器使用,


$('.#txt_dateDebut').datepicker({

beforeShowDay:function(Date){

var curr_date = Date.getDate();

var curr_month = Date.getMonth()+1;

var curr_year = Date.getFullYear();        

var curr_date=curr_month+'/'+curr_date+'/'+curr_year;        


if (datesForDisable.indexOf(curr_date)>-1) return false;        

}

});


查看完整回答
反對 回復 2021-11-19
  • 2 回答
  • 0 關注
  • 187 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號