Bootstrap-select jQuery 插件 Bootstrap 4

Bootstrap-select jQuery plugin with Bootstrap 4

我是 Bootstrap 的新手,尝试将 Bootstrap-Select 与 Bootstrap 4 一起使用(可以让它与 Bootstrap 3 一起使用) https://developer.snapappointments.com/bootstrap-select/

但是,我对 Bootstrap 和 select 需要的不同组件感到困惑。有时 select 不打开,有时 select 打开但没有搜索。我猜需要的组件是错误的,但我没有经验可以看出问题所在。

如果有人能提供帮助就太好了,已经谢谢了^^

<html>
<head>
    <meta charset="utf-8">
    <!-- Bootstrap -->
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">

    <!-- Own CSS -->
    <link rel="stylesheet" type="text/css" href="templates/style.css" media="screen" />
</head>

<body>
    <select class="selectpicker" data-live-search="true">
        <option disabled="disabled" selected>- Select -</option>
        <optgroup label="Main Options">
            <option value="all">All Models</option>
            <option value="final">Final Models</option>
            <option value="prepared">Prepared Models</option>
        </optgroup>
    </select>

    <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script>
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin="anonymous"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.12.1/js/bootstrap-select.js"></script>
</body>
</html>

如果您正在使用 bootstrap 4 您需要使用 bootstrap-select v1.13.0+

Bootstrap 4 only works with bootstrap-select v1.13.0+. By default, bootstrap-select automatically detects the version of Bootstrap being used. However, there are some instances where the version detection won't work. See the documentation for more information.

<html>
<head>
    <meta charset="utf-8">
    <!-- Bootstrap -->
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.5.3/dist/css/bootstrap.min.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-select@1.13.14/dist/css/bootstrap-select.min.css">

    <!-- Own CSS -->
    <!-- <link rel="stylesheet" type="text/css" href="templates/style.css" media="screen" /> -->
</head>

<body>
    <select class="selectpicker">
        <option disabled="disabled" selected>- Select -</option>
        <optgroup label="Main Options">
            <option value="all">All Models</option>
            <option value="final">Final Models</option>
            <option value="prepared">Prepared Models</option>
        </optgroup>
    </select>

    <script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js"></script>
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/bootstrap-select@1.13.14/dist/js/bootstrap-select.min.js"></script>
</body>
</html>