Laravel如何在模式上初始化Datepicker

时间:2019-06-19 11:45:24

标签: javascript jquery laravel datepicker

我有一个MaxSessions 1000模式,我需要jquery-datepicker才能工作,但由于某种原因,日期选择器未初始化。

laravel

然后,在我的app.js中执行:

@push('modals')
 <div class="modal fade" tabindex="-1" role="dialog" id="uploadModal">
    <div class="modal-dialog modal-lg" role="document">
      <form method="POST" action="{{ route('application.store') }}">
         <div class="modal-content">
           <input name="birthyear" type="text" class="form-control" autocomplete="birthyear" required />
         </div>
       ...
      </form>
   </div>
</div>

但是什么也没发生!?!我也尝试设置ID,但没有区别。

有人有线索吗?

1 个答案:

答案 0 :(得分:1)

您的视图。我通过添加id="birthyear"

对其进行了修改
@push('modals')
 <div class="modal fade" tabindex="-1" role="dialog" id="uploadModal">
    <div class="modal-dialog modal-lg" role="document">
      <form method="POST" action="{{ route('application.store') }}">
         <div class="modal-content">
           <input name="birthyear" id="birthyear" type="text" class="form-control" autocomplete="birthyear" required />
         </div>
       ...
      </form>
   </div>
</div>

javascript代码。我打电话给bootstrap CDN的日期选择器。我相信您的布局标题文件中必须包含@yield('scripts')

@section('scripts')
 <script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.5.0/js/bootstrap-datepicker.js"></script>

 //process date of birth
        $(document).ready(function () {

                $('#birthyear').datepicker({
                    format: "yyyy-mm-dd"
                });  

            });

        $('#birthyear').datepicker({
        autoclose: true,  
        format: "yyyy-mm-dd"
        }); 
@stop