Select2 和 bootstrap5 相关:为什么我的搜索栏无法正常工作?

Select2 and bootstrap5 related: why my search bar isnt working properly?

提问人:Francisco Macêdo 提问时间:11/4/2023 更新时间:11/7/2023 访问量:43

问:

我正在尝试制作一个人们可以搜索报告的网站,我试图通过使用 select2 使其变得更好,但不幸的是,它根本无法正常工作。有人可以帮我弄清楚吗?

html:

<!doctype html>
<html lang="pt-br">

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Página inicial</title>
    <link rel="stylesheet" href="css/index.css">

    <!-- select2  -->
    <link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/select2.min.css" rel="stylesheet" />
    <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/select2.min.js"></script>

    <!-- bootstrap -->
    <link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"
        integrity="sha384-T3c6CoIi6uLrA9TneNEoa7RxnatzjcDSCmG1MXxSR1GAsXEV/Dwwykc2MPK8M2HN" crossorigin="anonymous">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css">



</head>

<body>

    <!-- navbar do topo da tela com menu colapsável -->
    <header>
        <nav class="navbar navbar-expand-lg bg-body-tertiary">
            <div class="container-fluid">
                <a class="navbar-brand">
                    <img style="width: 320px;" src="img/logonavbar.png" alt="">
                </a>
                <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarText"
                    aria-controls="navbarText" aria-expanded="false" aria-label="Toggle navigation">
                    <span class="navbar-toggler-icon"></span>
                </button>
                <div class="collapse navbar-collapse" id="navbarText">
                    <ul class="navbar-nav me-auto mb-2 mb-lg-0">
                        <li class="nav-item">
                            <a class="nav-link active" aria-current="page" href="index.html">Página inicial</a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link" href="formulario.html">Personalizados</a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link" href="manual.html">Manuais</a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link" href="login.html">Sair</a>
                        </li>
                    </ul>
                    <form class="d-flex">
                        <input label="search" id="search" class="pesquisa form-control me-2" type="search"
                            placeholder="Relatórios do faturamento" aria-label="Search">
                            <button class="btn btn-outline-success" type="submit">Pesquisar</button>
                    </form>
                </div>
            </div>
        </nav>
    </header>
    <!-- fim do nav bar do topo -->

            <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"
                integrity="sha384-C6RzsynM9kWDrMNeT87bh95OGNyZPhcTNXj1NW7RuBCsyN/o0jlpcV8Qyq46cDfL"
                crossorigin="anonymous"></script>
            <script defer src="scripts/search.js"></script>
</body>

</html>

到目前为止的脚本:

var conteudo = [
  { id: 0, text: "relatorio de faturamento" },
  { id: 1, text: "relatorio de buscas" },
  { id: 2, text: "relatorio de vacinas" }
];

$(document).ready(function() {
  $('#search').select2({
    data: conteudo,
    minimumInputLength: 1, // Correção na ortografia
    width: '5%', // A largura de 5% pode ser muito pequena, ajuste conforme necessário
    multiple: true, // Defina como true para permitir múltiplas seleções
    placeholder: "relatorio de faturamento",
    templateResult: formatState, // Se você tem uma função formatState para personalizar o resultado
    theme: bootstrap-5
  });
});

我希望结果显示在下拉菜单中,然后将用户重定向到另一个页面。

引导-5 jquery-select2

评论


答: 暂无答案