首页 > 解决方案 > Laravel 中的引导日期选择器

问题描述

我使用 Laravel 引导程序和日期选择器,如下所示,这是代码,我已经确保日期格式正确运行,但是 todayHighlight: false 不起作用,容器也不能正常工作

<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css" integrity="sha384-9aIt2nRpC12Uk9gS9baDl411NQApFmC26EwAOH8WgZl5MYYxFfc+NcPb1dKGj7Sk" crossorigin="anonymous">

<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/js/bootstrap.min.js" integrity="sha384-OgVRvuATP1z7JjHLkuOU7Xw704+h835Lr+6QL9UvYjZE3Ipu6Tp75j7Bh/kR0JKI" crossorigin="anonymous"></script>

<link rel="stylesheet" href="https://code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css"> 
<script src="https://code.jquery.com/jquery-1.10.2.js"></script>
<script src="https://code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
<script>
    $(document).ready(function(){
        $('.datepicker_modal').datepicker({
            dateFormat: 'dd-mm-yy',
            container: $(this).closest('.dateContainer'),
            todayHighlight: false
        });
    });
</script>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <button type="button" class="btn btn-success mx-1" data-toggle="modal" data-placement="bottom" title="Approve" data-target="#accept_1">
        Click to Show
    </button>
    <div class="modal fade" id="accept_1" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle" aria-hidden="true">
        <div class="modal-dialog modal-dialog-centered" role="document">
          <div class="modal-accept modal-content">
            <div class="modal-header bg-success text-light">
              <h5 class="modal-title" id="exampleModalLongTitle"><strong>ACCEPT </strong></h5>
              <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                          <span aria-hidden="true">&times;</span>
                      </button>
            </div>
            <form method="POST" action="">
              <div class="modal-body">
                <div class="form-group dateContainer">
                  <label for="date_pick">Date</label>
                  <input id="date_pick" placeholder="DD-MM-YYYY" type="text" class="form-control datepicker_modal" name="date_pick" autocomplete="off" required>
                </div>
              </div>
              <div class="modal-footer d-flex justify-content-center">
                <button type="button" class="btn btn-danger" data-dismiss="modal">CANCEL</button>
                <button type="submit" class="btn btn-success">ACCEPT</button>
              </div>
            </form>
          </div>
        </div>
      </div>
</body>
</html>

但是在我的 Laravel 项目中,日期选择器是浮动的,并且仍然突出显示当前日期 有什么想法可以解决这个问题吗?

标签: javascriptlaravelbootstrap-4

解决方案


添加startDate你的js:

<script>
    $(document).ready(function(){
        $('.datepicker_modal').datepicker({
            dateFormat: 'dd-mm-yy',
            startDate: "12-12-2020",
            container:'#myModalId',
            todayHighlight: false
        });
    });
</script>

容器属性可以解决位置:

<input id="date_pick" placeholder="DD-MM-YYYY" type="text" data-date-container='#myModalId' class="form-control datepicker_modal" name="date_pick" autocomplete="off" required>

推荐阅读