简体   繁体   English

无法自定义bootstrap-datepicker

[英]Not able to customize bootstrap-datepicker

I am trying to customize the calendar, but it seems that it is not taking into account the customization, such as displaying the today button or ignoring past dates. 我正在尝试自定义日历,但似乎没有考虑到自定义,例如显示“今天”按钮或忽略过去的日期。 I tried the following: in the head 我尝试了以下方法:

<link href="css/bootstrap.min.css" rel="stylesheet">
<link href="css/bootstrap-datepicker3.min.css" rel="stylesheet">

in the top body 在上身

<script src="js/jquery.js"></script>

<!-- Bootstrap Core JavaScript -->
<script src="js/bootstrap.min.js"></script>
<script src="js/bootstrap-datepicker.min.js"></script>

Then in the form: 然后以以下形式:

    <script>
        $('.datepicker').datepicker({
            startDate: 0,
            todayBtn: "linked"
        });
    </script>
    <div class="form-group">
        <div class="input-group date" data-provide="datepicker">
            <input type="text" class="form-control" placeholder="Date *" id="caldate" required data-validation-required-message="Please choose date.">
            <span class="input-group-addon">
                <i class="glyphicon glyphicon-th"></i>
            </span>
            <p class="help-block text-danger"></p>
        </div>
    </div>

However, I still do not get the 'Today' button. 但是,我仍然没有获得“今天”按钮。 I am not sure if the reason is because the javascript code is not correct? 我不确定原因是否是因为javascript代码不正确? (not calling the calendar correctly) or misplaced? (未正确调用日历)或放错位置了?

Basically, your jQuery call with todayBtn option isn't really pointing to your input. 基本上,您的带有todayBtn选项的jQuery调用并不是真正指向您的输入。 The datepicker functionality you're seeing is based on your html. 您看到的datepicker功能基于您的html。 I moved the script after the elements (so it runs after the target elements are in the DOM) and changed the jQuery call to find the correct element. 我将脚本移到了元素之后(因此它在目标元素位于DOM中之后运行),并更改了jQuery调用以查找正确的元素。 Also, I believe the startDate option should be a date so I changed it from 0 to '3/16/2016' . 另外,我相信startDate选项应该是一个日期,因此我将其从0更改为'3/16/2016' The original html is unchanged... 原始html不变...

<div class="form-group">
  <div class="input-group date" data-provide="datepicker">
    <input type="text" class="form-control"
      placeholder="Date *" id="caldate" required data-validation-required-message="Please choose date.">
    <span class="input-group-addon">
      <i class="glyphicon glyphicon-th"></i>
    </span>
    <p class="help-block text-danger"></p>
  </div>
</div>

<script>
  $("div.input-group.date").datepicker({
    startDate: '3/1/2016',
    todayBtn: "linked"
  });
</script>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM