{"id":90,"date":"2025-11-22T09:49:39","date_gmt":"2025-11-22T01:49:39","guid":{"rendered":"https:\/\/www.52runoob.com\/?p=90"},"modified":"2025-11-22T09:49:39","modified_gmt":"2025-11-22T01:49:39","slug":"html5-%e6%90%9c%e7%b4%a2%e6%a1%86search-box%e8%af%a6%e8%a7%a3","status":"publish","type":"post","link":"https:\/\/www.52runoob.com\/index.php\/2025\/11\/22\/html5-%e6%90%9c%e7%b4%a2%e6%a1%86search-box%e8%af%a6%e8%a7%a3\/","title":{"rendered":"HTML5 \u641c\u7d22\u6846Search Box\u8be6\u89e3"},"content":{"rendered":"\n<p>\u4e0b\u9762\u7ed9\u4f60\u4e00\u4efd <strong>HTML5 \u641c\u7d22\u6846\uff08Search Box\uff09\u6700\u5168\u8be6\u89e3<\/strong>\uff1a\u5305\u542b\u8bed\u6cd5\u3001\u5c5e\u6027\u3001\u4e8b\u4ef6\u3001\u79fb\u52a8\u7aef\u7279\u6027\u3001\u81ea\u52a8\u5b8c\u6210\u3001\u6837\u5f0f\u7f8e\u5316\u3001\u5e38\u89c1\u9519\u8bef\u3001\u5b8c\u6574\u793a\u4f8b\u7b49\uff0c\u4e00\u6b21\u641e\u61c2\u641c\u7d22\u6846\u7684\u6240\u6709\u5b9e\u6218\u7528\u6cd5\uff01<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading\">\ud83d\udd0d <strong>\u4e00\u3001HTML5 \u641c\u7d22\u6846\u662f\u4ec0\u4e48\uff1f<\/strong><\/h1>\n\n\n\n<p>HTML5 \u63d0\u4f9b\u4e13\u95e8\u7528\u4e8e\u641c\u7d22\u7684\u8f93\u5165\u6846\u7c7b\u578b\uff1a<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n&amp;lt;input type=&quot;search&quot;&gt;\n\n<\/pre><\/div>\n\n\n<p>\u5b83\u4e0e <code>text<\/code> \u7c7b\u578b\u7c7b\u4f3c\uff0c\u4f46\u9488\u5bf9\u201c\u641c\u7d22\u201d\u573a\u666f\u505a\u4e86\u4f18\u5316\uff0c\u5c24\u5176\u662f\u5728 <strong>\u79fb\u52a8\u7aef\u6d4f\u89c8\u5668<\/strong> \u4e0a\u8868\u73b0\u66f4\u597d\u3002<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading\">\ud83e\udde9 <strong>\u4e8c\u3001\u57fa\u672c\u7528\u6cd5<\/strong><\/h1>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n&amp;lt;input type=&quot;search&quot; placeholder=&quot;\u641c\u7d22\u5185\u5bb9...&quot;&gt;\n\n<\/pre><\/div>\n\n\n<p>\u7279\u70b9\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u81ea\u5e26\u641c\u7d22\u8bed\u4e49\uff08\u5bf9 SEO \u548c\u65e0\u969c\u788d\u53cb\u597d\uff09<\/li>\n\n\n\n<li>\u79fb\u52a8\u7aef\u4f1a\u663e\u793a\u5e26\u201c\u641c\u7d22\u201d\u6216\u201c\u524d\u5f80\u201d\u7684\u952e\u76d8<\/li>\n\n\n\n<li>\u90e8\u5206\u6d4f\u89c8\u5668\u53f3\u4fa7\u9ed8\u8ba4\u663e\u793a\u6e05\u7a7a\u6309\u94ae\uff08\u00d7\uff09<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading\">\u2699\ufe0f <strong>\u4e09\u3001\u652f\u6301\u7684 HTML5 \u5c5e\u6027\u8be6\u89e3<\/strong><\/h1>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>\u5c5e\u6027\u540d<\/th><th>\u8bf4\u660e<\/th><th>\u793a\u4f8b<\/th><\/tr><\/thead><tbody><tr><td><code>placeholder<\/code><\/td><td>\u641c\u7d22\u6846\u63d0\u793a\u6587\u5b57<\/td><td><code>&lt;input placeholder=\"\u8bf7\u8f93\u5165\u5173\u952e\u8bcd\"&gt;<\/code><\/td><\/tr><tr><td><code>autocomplete<\/code><\/td><td>\u81ea\u52a8\u8865\u5168 on\/off<\/td><td><code>autocomplete=\"off\"<\/code><\/td><\/tr><tr><td><code>autofocus<\/code><\/td><td>\u9875\u9762\u52a0\u8f7d\u81ea\u52a8\u805a\u7126<\/td><td><code>autofocus<\/code><\/td><\/tr><tr><td><code>value<\/code><\/td><td>\u9ed8\u8ba4\u641c\u7d22\u5185\u5bb9<\/td><td><code>value=\"\u624b\u673a\"<\/code><\/td><\/tr><tr><td><code>required<\/code><\/td><td>\u4e0d\u80fd\u4e3a\u7a7a<\/td><td><code>required<\/code><\/td><\/tr><tr><td><code>maxlength<\/code><\/td><td>\u6700\u5927\u5b57\u6570\u9650\u5236<\/td><td><code>maxlength=\"20\"<\/code><\/td><\/tr><tr><td><code>pattern<\/code><\/td><td>\u6b63\u5219\u9a8c\u8bc1<\/td><td><code>pattern=\"[A-Za-z]+\"<\/code><\/td><\/tr><tr><td><code>name<\/code><\/td><td>\u63d0\u4ea4\u6570\u636e\u5b57\u6bb5\u540d<\/td><td><code>name=\"keyword\"<\/code><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>\u793a\u4f8b\uff1a<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n&amp;lt;input type=&quot;search&quot; name=&quot;q&quot; placeholder=&quot;\u641c\u7d22&quot; required autocomplete=&quot;off&quot;&gt;\n\n<\/pre><\/div>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading\">\ud83d\udd25 <strong>\u56db\u3001\u5e38\u7528\u4e8b\u4ef6\uff08Search \u4e13\u7528 + Input \u901a\u7528\uff09<\/strong><\/h1>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>\u4e8b\u4ef6<\/th><th>\u8bf4\u660e<\/th><\/tr><\/thead><tbody><tr><td><code>input<\/code><\/td><td>\u8f93\u5165\u8fc7\u7a0b\u4e2d\u5b9e\u65f6\u89e6\u53d1\uff08\u7528\u4e8e\u641c\u7d22\u5efa\u8bae\uff09<\/td><\/tr><tr><td><code>change<\/code><\/td><td>\u8f93\u5165\u5b8c\u6210\u540e\u6539\u53d8<\/td><\/tr><tr><td><code>search<\/code><\/td><td>\u7528\u6237\u70b9\u51fb\u641c\u7d22\u6309\u94ae\u6216\u6e05\u9664\u6309\u94ae\u65f6\u89e6\u53d1<\/td><\/tr><tr><td><code>focus<\/code> \/ <code>blur<\/code><\/td><td>\u805a\u7126 \/ \u5931\u7126<\/td><\/tr><tr><td><code>keydown<\/code><\/td><td>\u6309\u952e\u4e8b\u4ef6\uff08\u76d1\u542c Enter\uff09<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>\u76d1\u542c\u641c\u7d22\u4e8b\u4ef6\uff1a<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\ndocument.getElementById(&quot;search&quot;).addEventListener(&quot;search&quot;, function () {\n    console.log(&quot;\u7528\u6237\u63d0\u4ea4\u6216\u6e05\u9664\u4e86\u641c\u7d22&quot;);\n});\n\n<\/pre><\/div>\n\n\n<p>\u76d1\u542c\u56de\u8f66\u952e\uff1a<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nsearchInput.addEventListener(&quot;keydown&quot;, e =&gt; {\n    if (e.key === &quot;Enter&quot;) {\n        console.log(&quot;\u6309\u4e0b\u56de\u8f66\uff1a\u6267\u884c\u641c\u7d22\u903b\u8f91&quot;);\n    }\n});\n\n<\/pre><\/div>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading\">\ud83c\udfaf <strong>\u4e94\u3001\u641c\u7d22\u6846\u7684 CSS \u7f8e\u5316<\/strong><\/h1>\n\n\n\n<p>\u9ed8\u8ba4\u6837\u5f0f\u6bd4\u8f83\u6734\u7d20\uff0c\u901a\u5e38\u9700\u8981\u81ea\u5b9a\u4e49\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u2714 \u5706\u89d2\u641c\u7d22\u6846<\/h3>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n.search-box {\n    width: 100%;\n    padding: 10px 15px;\n    border-radius: 25px;\n    border: 1px solid #ccc;\n    font-size: 16px;\n}\n\n<\/pre><\/div>\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n&amp;lt;input type=&quot;search&quot; class=&quot;search-box&quot; placeholder=&quot;\u641c\u7d22\u5185\u5bb9&quot;&gt;\n\n<\/pre><\/div>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">\u2714 \u5e26\u56fe\u6807\u7684\u641c\u7d22\u6846<\/h3>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n&amp;lt;div class=&quot;search-container&quot;&gt;\n    &amp;lt;span class=&quot;icon&quot;&gt;\ud83d\udd0d&amp;lt;\/span&gt;\n    &amp;lt;input type=&quot;search&quot; id=&quot;search&quot; placeholder=&quot;\u641c\u7d22\u5185\u5bb9\u2026&quot;&gt;\n&amp;lt;\/div&gt;\n\n<\/pre><\/div>\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n.search-container {\n    position: relative;\n    width: 100%;\n}\n.search-container .icon {\n    position: absolute;\n    left: 10px;\n    top: 10px;\n}\n.search-container input {\n    width: 100%;\n    padding: 10px 40px;\n    border-radius: 22px;\n    border: 1px solid #ccc;\n}\n\n<\/pre><\/div>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">\u2714 \u53bb\u6389 Safari \u9ed8\u8ba4\u6e05\u9664\u6309\u94ae ( \u00d7 )<\/h3>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\ninput&#x5B;type=&quot;search&quot;]::-webkit-search-cancel-button {\n    display: none;\n}\n\n<\/pre><\/div>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading\">\ud83d\udce1 <strong>\u516d\u3001\u8f93\u5165\u641c\u7d22\u5efa\u8bae\uff08\u8054\u60f3\u8bcd\uff09\u5b9e\u73b0\u65b9\u5f0f<\/strong><\/h1>\n\n\n\n<h3 class=\"wp-block-heading\">1. \u9759\u6001\u5efa\u8bae\u5217\u8868<\/h3>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n&amp;lt;input id=&quot;search&quot; type=&quot;search&quot; list=&quot;suggest&quot;&gt;\n&amp;lt;datalist id=&quot;suggest&quot;&gt;\n    &amp;lt;option value=&quot;iPhone&quot;&gt;\n    &amp;lt;option value=&quot;\u5c0f\u7c73\u624b\u673a&quot;&gt;\n    &amp;lt;option value=&quot;\u534e\u4e3a&quot;&gt;\n&amp;lt;\/datalist&gt;\n\n<\/pre><\/div>\n\n\n<p>\u6d4f\u89c8\u5668\u4f1a\u81ea\u52a8\u5f39\u51fa\u5efa\u8bae\u3002<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">2. \u52a8\u6001 Ajax \u641c\u7d22\u5efa\u8bae\uff08\u5e38\u7528\u4e8e\u7535\u5546\uff09<\/h3>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nsearchInput.addEventListener(&quot;input&quot;, function () {\n    fetch(&quot;\/api\/search?kw=&quot; + this.value)\n        .then(res =&gt; res.json())\n        .then(list =&gt; {\n            suggestionBox.innerHTML = list.map(v =&gt; `&amp;lt;div&gt;${v}&amp;lt;\/div&gt;`).join(&quot;&quot;);\n        });\n});\n\n<\/pre><\/div>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading\">\ud83d\udcf1 <strong>\u4e03\u3001\u79fb\u52a8\u7aef\u641c\u7d22\u6846\u4f18\u5316<\/strong><\/h1>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>\u573a\u666f<\/th><th>\u65b9\u6cd5<\/th><\/tr><\/thead><tbody><tr><td>\u8c03\u6574\u952e\u76d8\u4e3a\u201c\u641c\u7d22\u201d\u6309\u94ae<\/td><td><code>input type=\"search\"<\/code> \u81ea\u52a8\u652f\u6301<\/td><\/tr><tr><td>iOS \u5fae\u8c03<\/td><td><code>-webkit-appearance: none;<\/code><\/td><\/tr><tr><td>\u81ea\u52a8\u7126\u70b9<\/td><td><code>autofocus<\/code><\/td><\/tr><tr><td>\u81ea\u52a8\u5173\u95ed\u952e\u76d8<\/td><td>\u5931\u7126 <code>input.blur()<\/code><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading\">\u2757 \u516b\u3001\u5e38\u89c1\u95ee\u9898\u4e0e\u89e3\u51b3\u65b9\u6848<\/h1>\n\n\n\n<h3 class=\"wp-block-heading\">1. \u641c\u7d22\u6846\u70b9\u51fb\u653e\u5927\u955c\u56fe\u6807\u4e0d\u89e6\u53d1\uff1f<\/h3>\n\n\n\n<p>\u2192 \u4f7f\u7528\u4e8b\u4ef6\u4ee3\u7406\u6216\u76d1\u542c\u5bb9\u5668\u70b9\u51fb<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">2. iOS \u641c\u7d22\u6846\u9ed8\u8ba4\u5706\u89d2\u592a\u5927\uff1f<\/h3>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\ninput&#x5B;type=&quot;search&quot;] {\n    -webkit-appearance: none;\n    border-radius: 0;\n}\n\n<\/pre><\/div>\n\n\n<h3 class=\"wp-block-heading\">3. autocomplete \u5173\u4e0d\u6389\uff1f<\/h3>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n&amp;lt;input autocomplete=&quot;off&quot; autocorrect=&quot;off&quot; autocapitalize=&quot;off&quot; spellcheck=&quot;false&quot;&gt;\n\n<\/pre><\/div>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading\">\u2b50 \u4e5d\u3001\u5b8c\u6574\u53ef\u8fd0\u884c\u793a\u4f8b\uff08\u5e26\u56fe\u6807 + \u641c\u7d22\u4e8b\u4ef6 + \u56de\u8f66\u641c\u7d22\uff09<\/h1>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n&amp;lt;!DOCTYPE html&gt;\n&amp;lt;html lang=&quot;zh-CN&quot;&gt;\n&amp;lt;head&gt;\n&amp;lt;meta charset=&quot;UTF-8&quot;&gt;\n&amp;lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1.0&quot;&gt;\n&amp;lt;title&gt;\u641c\u7d22\u6846\u793a\u4f8b&amp;lt;\/title&gt;\n\n&amp;lt;style&gt;\n    .search-box {\n        position: relative;\n        width: 100%;\n    }\n    .search-box input {\n        width: 100%;\n        padding: 10px 35px;\n        border-radius: 25px;\n        border: 1px solid #ccc;\n        font-size: 16px;\n    }\n    .search-box .icon {\n        position: absolute;\n        left: 12px;\n        top: 10px;\n        font-size: 18px;\n        color: #888;\n    }\n&amp;lt;\/style&gt;\n&amp;lt;\/head&gt;\n\n&amp;lt;body&gt;\n\n&amp;lt;h3&gt;HTML5 Search Box \u793a\u4f8b&amp;lt;\/h3&gt;\n\n&amp;lt;div class=&quot;search-box&quot;&gt;\n    &amp;lt;span class=&quot;icon&quot;&gt;\ud83d\udd0d&amp;lt;\/span&gt;\n    &amp;lt;input id=&quot;searchInput&quot; type=&quot;search&quot; placeholder=&quot;\u641c\u7d22\u5546\u54c1\u3001\u5185\u5bb9\u2026&quot;&gt;\n&amp;lt;\/div&gt;\n\n&amp;lt;div id=&quot;result&quot; style=&quot;margin-top: 20px;&quot;&gt;&amp;lt;\/div&gt;\n\n&amp;lt;script&gt;\nconst search = document.getElementById(&quot;searchInput&quot;);\nconst result = document.getElementById(&quot;result&quot;);\n\nsearch.addEventListener(&quot;keydown&quot;, e =&gt; {\n    if (e.key === &quot;Enter&quot;) {\n        result.innerHTML = &quot;\u4f60\u641c\u7d22\u4e86\uff1a&quot; + search.value;\n    }\n});\n\nsearch.addEventListener(&quot;search&quot;, () =&gt; {\n    result.innerHTML = &quot;\u641c\u7d22\u6846\u6e05\u7a7a\u6216\u63d0\u4ea4\uff1a&quot; + search.value;\n});\n&amp;lt;\/script&gt;\n\n&amp;lt;\/body&gt;\n&amp;lt;\/html&gt;\n\n<\/pre><\/div>","protected":false},"excerpt":{"rendered":"<p>\u4e0b\u9762\u7ed9\u4f60\u4e00\u4efd HTML5 \u641c\u7d22\u6846\uff08Search Box\uff09\u6700\u5168\u8be6\u89e3\uff1a\u5305\u542b\u8bed\u6cd5\u3001\u5c5e\u6027&#8230; <a class=\"more-link\" href=\"https:\/\/www.52runoob.com\/index.php\/2025\/11\/22\/html5-%e6%90%9c%e7%b4%a2%e6%a1%86search-box%e8%af%a6%e8%a7%a3\/\">Continue Reading &rarr;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[],"class_list":["post-90","post","type-post","status-publish","format-standard","hentry","category-html5"],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/posts\/90","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/comments?post=90"}],"version-history":[{"count":1,"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/posts\/90\/revisions"}],"predecessor-version":[{"id":91,"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/posts\/90\/revisions\/91"}],"wp:attachment":[{"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/media?parent=90"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/categories?post=90"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/tags?post=90"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}