javascript 我如何从jquery得到上个月的日期?[duplicate]

ubof19bj  于 2023-01-04  发布在  Java
关注(0)|答案(1)|浏览(169)
    • 此问题在此处已有答案**:

jQuery Date Picker - disable past dates(16个答案)
昨天关门了。
我必须选择日期从上个月和前几个月的日期与此代码是不能回到过去的日期如何进行下一步?

let firstDay = new Date();
$('#date_filter_startmonthly').datepicker({
  startDate: firstDay,
  endDate: '+0d',
  todayHighlight: true,
  format: 'yyyy-mm-dd',
  orientation: 'bottom auto',
  autoclose: true,
  changeMonth: false,
  changeYear: false,
  stepMonths: false,
});
<div class="form-group mb-2">
  <label class="col-form-lable mb-0">Start Date:</label>
  <div id="date_filter_startmonthly" class="input-group date" data-target-input="nearest">
    <div data-target="#date_filter_startmonthly" data-toggle="datepicker" class="input-group datetimepicker">
      <input type="text" class="form-control form-control-sm" name="cb_sdate" placeholder="YYYY-MM-DD">
      <div class="input-group-addon "></div>
    </div>
  </div>
</div>



<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.13.2/jquery-ui.min.js" ></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.13.2/themes/base/jquery-ui.min.css" />
erhoui1w

erhoui1w1#

1.包含jQuery脚本、jQueryUI脚本、jQueryUI样式(必须保持包含脚本的顺序)。
1.将日期选择器的选择器更改为$(#date_filter_startmonthly input),因为日期选择器应始终指向输入字段。
1.更改日期选择器 prop ,以便允许选择月份或年份。

$(document).ready(main);
function main(){
  $('#date_filter_startmonthly input').datepicker({
          todayHighlight: true,
          format: 'yyyy-mm-dd',
          orientation: 'bottom auto',
          autoclose: true,
  });
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script>
<link href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/themes/ui-lightness/jquery-ui.css" rel="stylesheet"/>

<div class="form-group mb-2">
  <label class="col-form-lable mb-0">Start Date:</label>
  <div id="date_filter_startmonthly" class="input-group date" data-target-input="nearest">
    <div data-target="#date_filter_startmonthly" data-toggle="datepicker"class="input-group datetimepicker">
      <input type="text" class="form-control form-control-sm date-input" name="cb_sdate" placeholder="YYYY-MM-DD">
      <div class="input-group-addon "></div>
    </div>
  </div>
</div>

相关问题