首页 > 解决方案 > jQuery datepicker:show 方法在 Bootstrap 模式下不起作用

问题描述

我希望 jQuery datepicker 默认显示在我的模态窗口中,但我得到的只是这个错误:

无法读取未定义的属性“左侧”

<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
      <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
      <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
</head>

<body>

<!-- Trigger the modal with a button -->
<button type="button" class="btn btn-info btn-lg" data-toggle="modal" data-target="#myModal">Open Modal</button>

<!-- Modal -->
<div id="myModal" class="modal fade" role="dialog">
  <div class="modal-dialog">

    <!-- Modal content-->
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal">&times;</button>
        <h4 class="modal-title">Modal Header</h4>
      </div>
      <div class="modal-body">
      <script>
        $( function() {
          $('#datepicker').datepicker({dateFormat: 'dd/mm/yy'}).datepicker('show');
        });
      </script>
        <p>Some text in the modal.</p>
        <input type="text" name="" id="datepicker">
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
      </div>
    </div>

  </div>
</div>

</body>
</html>

我怎样才能解决这个问题 ?
注意:不使用 show 方法时,它可以正常工作。

标签: jquerybootstrap-modaljquery-ui-datepicker

解决方案


推荐阅读