{"id":2027,"date":"2023-03-25T14:33:59","date_gmt":"2023-03-25T06:33:59","guid":{"rendered":""},"modified":"2023-03-25T14:33:59","modified_gmt":"2023-03-25T06:33:59","slug":"Bootstrap \u81ea\u52a8\u5b8c\u6210\u641c\u7d22","status":"publish","type":"post","link":"https:\/\/bianchenghao6.com\/2027.html","title":{"rendered":"Bootstrap \u81ea\u52a8\u5b8c\u6210\u641c\u7d22"},"content":{"rendered":"


\n <\/head>
\n <\/p>\n

\n

Bootstrap \u81ea\u52a8\u5b8c\u6210\u641c\u7d22<\/h1>\n<\/p><\/div>\n

Bootstrap \u81ea\u52a8\u5b8c\u6210\u641c\u7d22<\/h2>\n
\n \u5728\u672c\u8282\u4e2d\uff0c\u6211\u4eec\u5c06\u4f7f\u7528Bootstrap Typeahead JS\u8fdb\u884c\u52a8\u6001\u81ea\u52a8\u5b8c\u6210\u641c\u7d22\u3002\u63d0\u524d\u8f93\u5165\u4e5f\u53ef\u4ee5\u79f0\u4e3a\u81ea\u52a8\u5efa\u8bae\u6216\u81ea\u52a8\u5b8c\u6210\u3002\u5b83\u662f\u4e00\u79cd\u7528\u4e8e\u8bed\u8a00\u9884\u6d4b\u7684\u5de5\u5177\u3002\u8bb8\u591a\u641c\u7d22\u754c\u9762\u90fd\u4f7f\u7528\u6b64\u5de5\u5177\u3002\u5f53\u5ba2\u6237\u5728\u641c\u7d22\u680f\u4e2d\u952e\u5165\u5185\u5bb9\u65f6\uff0c\u4ed6\u4eec\u5c06\u83b7\u5f97\u4e00\u4e9b\u5efa\u8bae\u3002\u5f53\u7528\u6237\u5728\u641c\u7d22\u680f\u4e2d\u952e\u5165\u5185\u5bb9\u65f6\uff0cTypeahead\u4f1a\u63d0\u4f9b\u9884\u6d4b\u3002\n <\/div>\n
\n \u73b0\u4ee3\u7684Web\u8868\u5355\u5177\u6709\u975e\u5e38\u6d41\u884c\u7684\u641c\u7d22\u5de5\u5177\uff0c\u5373typeahead\u8f93\u5165\u5b57\u6bb5\u3002 Typeahead\u901a\u5e38\u7528\u4e8e\u6539\u5584\u7528\u6237\u4f53\u9a8c\u3002\u8be5\u5de5\u5177\u5728\u7528\u6237\u641c\u7d22\u5185\u5bb9\u6216\u586b\u5199\u8868\u5355\u65f6\u67e5\u770b\u7528\u6237\u8f93\u5165\u7684\u6587\u672c\u3002\u57fa\u4e8e\u8fd9\u4e9b\u5185\u5bb9\uff0cTypeahead\u5411\u7528\u6237\u63d0\u4f9b\u63d0\u793a\u548c\u53ef\u80fd\u9009\u62e9\u7684\u5217\u8868\u3002\u641c\u7d22\u53ef\u4ee5\u662f\u4efb\u4f55\u7c7b\u578b\u3002\u5f53\u6211\u4eec\u4f7f\u7528Typeahead\u65f6\uff0c\u6211\u4eec\u5c06\u51cf\u5c11\u6f5c\u5728\u7684\u9519\u8bef\uff0c\u5e76\u4e14\u8fd8\u53ef\u4ee5\u8282\u7701\u65f6\u95f4\uff0c\u56e0\u4e3a\u5728\u4f7f\u7528Typeahead\u65f6\uff0c\u7528\u6237\u7684\u62fc\u5199\u9519\u8bef\u5c06\u66f4\u5c11\u3002\n <\/div>\n
\n \u9996\u5148\uff0c\u6211\u4eec\u5c06\u521b\u5efa html \u5e03\u5c40\u3002\u6211\u4eec\u5c06\u6dfb\u52a0 JQuery \u548c\u5728Ajax.html\u6587\u4ef6\u4e2d\u63d0\u524d\u8f93\u5165Bootstrap \u3002\u5982\u679c\u5c1d\u8bd5\u5728\u8f93\u5165\u6846\u4e0a\u5199\u4e00\u4e9b\u5185\u5bb9\uff0c\u5219\u53ef\u4ee5\u8fdb\u884c\u52a8\u6001\u81ea\u52a8\u5b8c\u6210\u641c\u7d22\u3002\u901a\u8fc7\u4f7f\u7528Ajax\u8bf7\u6c42\u662f\u53ef\u80fd\u7684\u3002\u56e0\u6b64\uff0c\u5c06\u9996\u5148\u4f7f\u7528\u4ee5\u4e0b\u4ee3\u7801\u521b\u5efaajax.html\u6587\u4ef6:\n <\/div>\n
\n ajax.html:\n <\/div>\n
\n
<html lang=\"en\"<\/span>>\n<head>\n    <title> Example of Bootstrap Typeahead with Ajax <\/title>  \n    <link href=\"https:\/\/maxcdn.bootstrapcdn.com\/bootstrap\/3.3.6\/css\/bootstrap.min.css\"<\/span> rel=\"stylesheet\"<\/span>>\n    <script src=\"http:\/\/ajax.googleapis.com\/ajax\/libs\/jquery\/1.9.1\/jquery.js\"<\/span>><\/script>\n    <script src=\"https:\/\/cdnjs.cloudflare.com\/ajax\/libs\/bootstrap-3-typeahead\/4.0.1\/bootstrap3-typeahead.min.js\"<\/span>><\/script>  \n<\/head>\n<body>\n<div class=\"row\"<\/span>>\n    <div class=\"col-md-12 text-center\"<\/span>>\n        <br\/>\n        <h1> Example of Dynamic Autocomplete search using Bootstrap Typeahead JS<\/h1>   \n            <input class=\"typeahead form-control\"<\/span> style=\"margin:0px auto;width:300px;\"<\/span> type=\"text\"<\/span>>\n    <\/div>\n<\/div>\n<script type=\"text\/javascript\"<\/span>>\n    $('input.typeahead'<\/span>).typeahead<\/span>({\n        source:  function (query, process) {\n        return <\/span>$.get<\/span>('\/ajaxpro.php'<\/span>, { query: query }, function <\/span>(data) {\n                console.log<\/span>(data);\n                data = $.parseJSON<\/span>(data);\n                return <\/span>process(data);\n            });\n        }\n    });\n<\/script>\n<\/body>\n<\/html><\/pre>\n

<\/code>\n <\/div>\n

\n \u73b0\u5728\u6211\u4eec\u7684\u793a\u4f8b\u9700\u8981 JSON \u6570\u636e\u3002\u6211\u4eec\u5c06\u901a\u8fc7\u521b\u5efa\u4e00\u4e2a\u65b0\u9875\u9762\u5e76\u6839\u636eAjax\u8bf7\u6c42\u83b7\u5f97\u6b64\u529f\u80fd\u3002\u56e0\u6b64\uff0c\u5728\u4e0b\u9762\u7684\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u5c06\u518d\u521b\u5efa\u4e00\u9875ajaxpro.php\u6587\u4ef6\u3002\u4e4b\u540e\uff0c\u6211\u4eec\u5c06\u6dfb\u52a0\u4ee5\u4e0b\u4ee3\u7801:\n <\/div>\n
\n ajaxpro.php:\n <\/div>\n
\n
<?php\n    \n    define (DB_USER, \"root\"<\/span><\/span>);\n    define (DB_PASSWORD, \"root\");\n    define (DB_DATABASE, \"learn\"<\/span>);\n    define (DB_HOST, \"localhost\"<\/span>);\n    $mysqli = new <\/span>mysqli(DB_HOST, DB_USER, DB_PASSWORD, DB_DATABASE);\n    $sql = \"SELECT items.title FROM items \n            WHERE title LIKE '%\"<\/span>.$_GET['query'<\/span>].\"%'<\/span>\n            LIMIT 10\"; \n    $result = $mysqli->query($sql);\n    \n    s$json = [];\n    while($row = $result->fetch_assoc()){\n         $json[] = $row['title'<\/span>];\n    }\n    echo json_encode($json);<\/pre>\n

<\/code>\n <\/div>\n

\n \u6211\u4eec\u7684\u4ee5\u4e0a\u4ee3\u7801\u5df2\u51c6\u5907\u5c31\u7eea\uff0c\u53ef\u4ee5\u8fd0\u884c\u3002\u8fd0\u884c\u6b64\u4ee3\u7801\u65f6\uff0c\u5c06\u83b7\u5f97\u4ee5\u4e0b\u8f93\u51fa:\n <\/div>\n

Bootstrap \u81ea\u52a8\u5b8c\u6210\u641c\u7d22_https:\/\/bianchenghao6.com_\u3010Bootstrap \u6559\u7a0b\u3011_\u7b2c1\u5f20 <\/p>\n


\n

<\/body>
\n<\/html><\/p>\n","protected":false},"excerpt":{"rendered":"Bootstrap \u81ea\u52a8\u5b8c\u6210\u641c\u7d22zh-cn","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[163],"tags":[],"class_list":["post-2027","post","type-post","status-publish","format-standard","hentry","category-bootstrapjc"],"_links":{"self":[{"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/posts\/2027"}],"collection":[{"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/comments?post=2027"}],"version-history":[{"count":0,"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/posts\/2027\/revisions"}],"wp:attachment":[{"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/media?parent=2027"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/categories?post=2027"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/tags?post=2027"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}