(..).select2 不是函数

(..).select2 is not a function

我已经尝试了“Select2() is not a function”的解决方案,但我仍然无法确定问题出在哪里..我在我的控制台中收到了这个警告,我不知道它是否与有没有问题

A cookie associated with a cross-site resource at http://cloudflare.com/ was set without the SameSite attribute. A future release of Chrome will only deliver cookies with cross-site requests if they are set with SameSite=None and Secure. You can review cookies in developer

<html>
<head>
  <meta charset="utf-8">
  <script src="https://code.jquery.com/jquery-1.12.3.js" integrity="sha256-1XMpEtA4eKXNNpXcJ1pmMPs8JV+nwLdEqwiJeCQEkyc=" crossorigin="anonymous"></script>
  <link href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.1/css/select2.min.css" rel="stylesheet" />
  <script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.1/js/select2.min.js"></script>
  <script src="/assets/newDailyDetail.js"></script>
  <link rel="stylesheet" href="/css/new.css">
  <link rel="stylesheet" href="/css/css/bootstrap.min.css">
</head>

<body>
  <select class="browser-default custom-select" name="childId" id="childName">
    <option disabled selected>Select the Child..</option>
    <% child.forEach((childItem) => { %>
      <option value="<%= childItem.childId %>">
        <%=childItem.childName %>
      </option>
      <%    })  %>
  </select>
  <script type="text/javascript">
    $(document).ready(function() {
      $('#childName').select2({

      })
    })
  </script>
</body>
</html>

DOM 还没有准备好。试试这个:

$(document).ready(function() {
    $('.js-example-basic-single').select2();
});

我已经解决了..我在我的 layOut 中使用了 jQuery 所以当我在我的 layOut.ejs 中删除 jquery cdn 时..它工作正常