{"id":49304,"date":"2024-12-02T11:14:05","date_gmt":"2024-12-02T03:14:05","guid":{"rendered":"https:\/\/fwq.ai\/blog\/49304\/"},"modified":"2024-12-02T11:14:05","modified_gmt":"2024-12-02T03:14:05","slug":"%e5%a6%82%e4%bd%95%e5%88%a9%e7%94%a8-jquery-ui-autocomplete-%e5%ae%9e%e7%8e%b0%e5%85%ac%e5%8f%b8%e5%90%8d%e7%a7%b0%e8%87%aa%e5%8a%a8%e5%a1%ab%e5%85%85%e5%8a%9f%e8%83%bd%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/49304\/","title":{"rendered":"\u5982\u4f55\u5229\u7528 jQuery UI autocomplete \u5b9e\u73b0\u516c\u53f8\u540d\u79f0\u81ea\u52a8\u586b\u5145\u529f\u80fd\uff1f"},"content":{"rendered":"<p><b><\/b> <\/p>\n<h1>\u5982\u4f55\u5229\u7528 jQuery UI autocomplete \u5b9e\u73b0\u516c\u53f8\u540d\u79f0\u81ea\u52a8\u586b\u5145\u529f\u80fd\uff1f<\/h1>\n<p>\u6765\u5230\u7c73\u4e91\u7684\u5927\u5bb6\uff0c\u76f8\u4fe1\u90fd\u662f\u7f16\u7a0b\u5b66\u4e60\u7231\u597d\u8005\uff0c\u5e0c\u671b\u5728\u8fd9\u91cc\u5b66\u4e60\u6587\u7ae0\u76f8\u5173\u7f16\u7a0b\u77e5\u8bc6\u3002\u4e0b\u9762\u672c\u7bc7\u6587\u7ae0\u5c31\u6765\u5e26\u5927\u5bb6\u804a\u804a\u300a\u5982\u4f55\u5229\u7528 jQuery UI autocomplete \u5b9e\u73b0\u516c\u53f8\u540d\u79f0\u81ea\u52a8\u586b\u5145\u529f\u80fd\uff1f\u300b\uff0c\u4ecb\u7ecd\u4e00\u4e0b\uff0c\u5e0c\u671b\u5bf9\u5927\u5bb6\u7684\u77e5\u8bc6\u79ef\u7d2f\u6709\u6240\u5e2e\u52a9\uff0c\u52a9\u529b\u5b9e\u6218\u5f00\u53d1\uff01<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241127\/17327018366746ee8c5ddf6.jpg\" class=\"aligncenter\" title=\"\u5982\u4f55\u5229\u7528 jQuery UI autocomplete \u5b9e\u73b0\u516c\u53f8\u540d\u79f0\u81ea\u52a8\u586b\u5145\u529f\u80fd\uff1f\u63d2\u56fe\" alt=\"\u5982\u4f55\u5229\u7528 jQuery UI autocomplete \u5b9e\u73b0\u516c\u53f8\u540d\u79f0\u81ea\u52a8\u586b\u5145\u529f\u80fd\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>\u516c\u53f8\u540d\u79f0\u81ea\u52a8\u586b\u5145<\/strong><\/p>\n<p><strong>\u95ee\u9898\uff1a<\/strong> \u5982\u4f55\u5b9e\u73b0\u586b\u5199\u516c\u53f8\u540d\u79f0\u65f6\u81ea\u52a8\u586b\u5145\u8be5\u516c\u53f8\u4fe1\u606f\u7684\u63d0\u793a\u529f\u80fd\uff1f<\/p>\n<p><strong>\u89e3\u7b54\uff1a<\/strong><\/p>\n<p>\u8981\u5b9e\u73b0\u516c\u53f8\u540d\u79f0\u81ea\u52a8\u586b\u5145\u529f\u80fd\uff0c\u53ef\u4ee5\u4f7f\u7528 jquery ui autocomplete \u63d2\u4ef6\u3002\u8be5\u63d2\u4ef6\u63d0\u4f9b\u4e86\u81ea\u52a8\u5b8c\u6210\u548c\u5efa\u8bae\u7684\u529f\u80fd\uff0c\u5b83\u53ef\u4ee5\u901a\u8fc7\u8f93\u5165\u6587\u672c\u65f6\u83b7\u53d6\u5efa\u8bae\u6765\u5e2e\u52a9\u7528\u6237\u5feb\u901f\u51c6\u786e\u5730\u8f93\u5165\u6570\u636e\u3002<\/p>\n<p><strong>\u4f7f\u7528 jquery ui autocomplete\uff1a<\/strong><\/p>\n<pre>&lt;input id=\"company-name\" type=\"text\" \/&gt;\n&lt;div id=\"company-info\"&gt;&lt;\/div&gt;<\/pre>\n<pre>$( \"#company-name\" ).autocomplete({\n  source: function( request, response ) {\n    $.ajax({\n      url: \"\/api\/companies\",\n      data: { term: request.term },\n      success: function( data ) {\n        response( data );\n      }\n    });\n  },\n  select: function( event, ui ) {\n    $.ajax({\n      url: \"\/api\/companies\/\" + ui.item.id,\n      success: function( data ) {\n        $( \"#company-info\" ).html( data.html );\n      }\n    });\n  }\n});<\/pre>\n<p><strong>\u4ee3\u7801\u8bf4\u660e\uff1a<\/strong><\/p>\n<ul>\n<li>\u521b\u5efa\u4e00\u4e2a\u8f93\u5165\u6846\uff08&lt;input&gt;\uff09\u5e76\u4e3a\u5176\u5206\u914d\u4e00\u4e2a id\uff0c\u4f8b\u5982 &#8220;company-name&#8221;\u3002<\/li>\n<li>\u4f7f\u7528 jquery ui autocomplete \u521d\u59cb\u5316\u8f93\u5165\u6846\uff0c\u5e76\u6307\u5b9a source \u9009\u9879\uff0c\u8be5\u9009\u9879\u8d1f\u8d23\u83b7\u53d6\u5efa\u8bae\u3002<\/li>\n<li>\u5728 source \u51fd\u6570\u4e2d\uff0c\u53d1\u9001 ajax \u8bf7\u6c42\u4ee5\u83b7\u53d6\u4e0e\u8f93\u5165\u6587\u672c\u5339\u914d\u7684\u516c\u53f8\u540d\u79f0\u5217\u8868\u3002<\/li>\n<li>\u5f53\u7528\u6237\u9009\u62e9\u4e00\u4e2a\u5efa\u8bae\u9879\u65f6\uff0c\u89e6\u53d1 select \u4e8b\u4ef6\u3002\u5728\u4e8b\u4ef6\u5904\u7406\u7a0b\u5e8f\u4e2d\uff0c\u53d1\u9001\u53e6\u4e00\u4e2a ajax \u8bf7\u6c42\u4ee5\u83b7\u53d6\u6709\u5173\u8be5\u516c\u53f8\u7684\u8be6\u7ec6\u4fe1\u606f\u3002<\/li>\n<li>\u5c06\u516c\u53f8\u8be6\u7ec6\u4fe1\u606f\u6ce8\u5165\u5230\u76ee\u6807\u5143\u7d20\uff08\u4f8b\u5982 &lt;div id=&#8221;company-info&#8221;&gt;) \u4e2d\u3002<\/li>\n<\/ul>\n<p>\u4eca\u5929\u5e26\u5927\u5bb6\u4e86\u89e3\u4e86\u7684\u76f8\u5173\u77e5\u8bc6\uff0c\u5e0c\u671b\u5bf9\u4f60\u6709\u6240\u5e2e\u52a9\uff1b\u5173\u4e8e\u6587\u7ae0\u7684\u6280\u672f\u77e5\u8bc6\u6211\u4eec\u4f1a\u4e00\u70b9\u70b9\u6df1\u5165\u4ecb\u7ecd\uff0c\u6b22\u8fce\u5927\u5bb6\u5173\u6ce8\u7c73\u4e91\u516c\u4f17\u53f7\uff0c\u4e00\u8d77\u5b66\u4e60\u7f16\u7a0b~<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5982\u4f55\u5229\u7528 jQuery UI autocomplete \u5b9e\u73b0\u516c\u53f8\u540d\u79f0\u81ea\u52a8\u586b\u5145\u529f\u80fd\uff1f \u6765\u5230\u7c73\u4e91\u7684\u5927\u5bb6\uff0c\u76f8\u4fe1\u90fd\u662f\u7f16\u7a0b\u5b66\u4e60\u7231\u597d\u8005\uff0c\u5e0c\u671b\u5728\u8fd9\u91cc\u5b66\u4e60\u6587\u7ae0\u76f8\u5173\u7f16\u7a0b\u77e5\u8bc6\u3002\u4e0b\u9762\u672c\u7bc7\u6587\u7ae0\u5c31\u6765\u5e26\u5927\u5bb6\u804a\u804a\u300a\u5982\u4f55\u5229\u7528 jQuery UI autocomplete \u5b9e\u73b0\u516c\u53f8\u540d\u79f0\u81ea\u52a8\u586b\u5145\u529f\u80fd\uff1f\u300b\uff0c\u4ecb\u7ecd\u4e00\u4e0b\uff0c\u5e0c\u671b\u5bf9\u5927\u5bb6\u7684\u77e5\u8bc6\u79ef\u7d2f\u6709\u6240\u5e2e\u52a9\uff0c\u52a9\u529b\u5b9e\u6218\u5f00\u53d1\uff01 \u516c\u53f8\u540d\u79f0\u81ea\u52a8\u586b\u5145 \u95ee\u9898\uff1a \u5982\u4f55\u5b9e\u73b0\u586b\u5199\u516c\u53f8\u540d\u79f0\u65f6\u81ea\u52a8\u586b\u5145\u8be5\u516c\u53f8\u4fe1\u606f\u7684\u63d0\u793a\u529f\u80fd\uff1f \u89e3\u7b54\uff1a \u8981\u5b9e\u73b0\u516c\u53f8\u540d\u79f0\u81ea\u52a8\u586b\u5145\u529f\u80fd\uff0c\u53ef\u4ee5\u4f7f\u7528 jquery ui autocomplete \u63d2\u4ef6\u3002\u8be5\u63d2\u4ef6\u63d0\u4f9b\u4e86\u81ea\u52a8\u5b8c\u6210\u548c\u5efa\u8bae\u7684\u529f\u80fd\uff0c\u5b83\u53ef\u4ee5\u901a\u8fc7\u8f93\u5165\u6587\u672c\u65f6\u83b7\u53d6\u5efa\u8bae\u6765\u5e2e\u52a9\u7528\u6237\u5feb\u901f\u51c6\u786e\u5730\u8f93\u5165\u6570\u636e\u3002 \u4f7f\u7528 jquery ui autocomplete\uff1a &lt;input id=&#8221;company-name&#8221; type=&#8221;text&#8221; \/&gt; &lt;div id=&#8221;company-info&#8221;&gt;&lt;\/div&gt; $( &#8220;#company-name&#8221; ).autocomplete({ source: function( request, response ) { $.ajax({ url: &#8220;\/api\/companies&#8221;, data: { term: request.term }, success: function( data ) { response( data ); } [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-49304","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/49304","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=49304"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/49304\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=49304"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=49304"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=49304"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}