{"id":9621,"date":"2020-10-26T01:05:12","date_gmt":"2020-10-25T17:05:12","guid":{"rendered":"https:\/\/www.zhangxinxu.com\/wordpress\/?p=9621"},"modified":"2020-10-26T16:13:54","modified_gmt":"2020-10-26T08:13:54","slug":"ios-safari-input-button-focus","status":"publish","type":"post","link":"https:\/\/www.zhangxinxu.com\/wordpress\/2020\/10\/ios-safari-input-button-focus\/","title":{"rendered":"\u7ec6\u8bf4iOS Safari\u4e0bfocus\u7684\u884c\u4e3a"},"content":{"rendered":"<p>by <a href=\"https:\/\/www.zhangxinxu.com\/\">zhangxinxu<\/a> from <a href=\"https:\/\/www.zhangxinxu.com\/wordpress\/?p=9621\">https:\/\/www.zhangxinxu.com\/wordpress\/?p=9621<\/a><br \/>\n\u672c\u6587\u6b22\u8fce\u5206\u4eab\u4e0e\u805a\u5408\uff0c\u5168\u6587\u8f6c\u8f7d\u5c31\u4e0d\u5fc5\u4e86\uff0c\u5c0a\u91cd\u7248\u6743\uff0c\u5708\u5b50\u5c31\u8fd9\u4e48\u5927\uff0c\u82e5\u6025\u7528\u53ef\u4ee5\u8054\u7cfb\u6388\u6743\u3002<\/p>\n<p><script>window.wxShareImgUrl = 'https:\/\/www.zhangxinxu.com\/study\/image\/share\/202010-ios-focus.png';<\/script><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/image.zhangxinxu.com\/image\/blog\/202010\/iso-safari-focus-cover.png\" width=\"480\" height=\"305\" alt=\"\u5c01\u9762\u56fe\u5360\u4f4d\u56fe\" class=\"alignright clip thumb size-medium\" \/><\/p>\n<p>iOS Safari\u6d4f\u89c8\u5668\u4e0b\u7684focus\u884c\u4e3a\u548c\u5176\u4ed6\u6d4f\u89c8\u5668\u90fd\u4e00\u4e9b\u660e\u663e\u4e0d\u4e00\u81f4\u7684\u5730\u65b9\uff0c\u6709\u65f6\u5019\u4f1a\u7ed9\u5f00\u53d1\u5e26\u6765\u56f0\u6270\uff0c\u8fd9\u91cc\u5c31\u8bf4\u8bf4\u76f8\u5173\u7684\u7ec6\u8282\u77e5\u8bc6\uff0c\u5747\u6e90\u81ea\u4e8e\u81ea\u5df1\u65e5\u5e38\u5f00\u53d1\u9047\u5230\u7684\u95ee\u9898\u3002<\/p>\n<h3>\u4e00\u3001button\u70b9\u51fb\u65e0\u6cd5focus<\/h3>\n<p><code>:focus-within<\/code>\u4f2a\u7c7b\u662f\u4e00\u4e2a\u975e\u5e38\u5b9e\u7528\u7684CSS\u4f2a\u7c7b\uff0c\u8be6\u89c1\u6211<span class=\"hidden\">\u5f20\u946b\u65ed<\/span>2\u5e74\u524d\u5199\u7684\u8fd9\u7bc7\u6587\u7ae0\u201c<a href=\"https:\/\/www.zhangxinxu.com\/wordpress\/2018\/01\/css-focus-within-pseudo-class-selector\/\">\u8be6\u7ec6\u4e86\u89e3CSS :focus-within\u4f2a\u7c7b\u53ca\u5176\u4ea4\u4e92\u5e94\u7528<\/a>\u201d\u3002<\/p>\n<p>\u8fd9\u4e2a\u4f2a\u7c7b\u5728Chrome\u548cFirefox\u6d4f\u89c8\u5668\u4e0b\u4f7f\u7528\u975e\u5e38OK\uff0c\u4f46\u662f\u5728Safari\u6d4f\u89c8\u5668\u4e0b\u5374\u6709\u5751\uff0c\u94fe\u63a5\u548c\u6309\u94ae\u660e\u660e\u70b9\u51fb\u4e86\uff0c\u5374\u4e0d\u80fd\u89e6\u53d1\u7956\u5148\u5143\u7d20\u7684<code>:focus-within<\/code>\u4f2a\u7c7b\u5339\u914d\u3002<\/p>\n<p>\u5343\u4e07\u4e0d\u8981\u8ba4\u4e3a\u662fSafari\u6d4f\u89c8\u5668\u4e0d\u652f\u6301<code>:focus-within<\/code>\u4f2a\u7c7b\uff0cSafari\u6d4f\u89c8\u5668\u652f\u6301\u5f88\u591a\u5e74\u4e86\uff0c\u517c\u5bb9\u6027\u5982\u4e0b\u56fe\u6240\u793a\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/image.zhangxinxu.com\/image\/blog\/202010\/2020-10-25_234658.png\" width=\"548\" height=\"254\" alt=\":focus-within\u4f2a\u7c7b\u6700\u65b0\u7684\u517c\u5bb9\u6027\" class=\"alignnone size-medium\" \/><\/p>\n<p>\u90a3\u4e3a\u4f55Safari\u6d4f\u89c8\u5668\u4e0b\u6ca1\u6709\u6548\u679c\u5462\uff1f<\/p>\n<p>\u539f\u56e0\u5c31\u5728\u4e8eSafari\u6d4f\u89c8\u5668\u4e0b\uff0c<code>&lt;a&gt;<\/code>\u94fe\u63a5\u5143\u7d20\u548c<code>&lt;button&gt;<\/code>\u6309\u94ae\u5143\u7d20\u5728\u70b9\u51fb\u7684\u65f6\u5019\uff0c\u662f\u4e0d\u4f1a\u6709<code>focus<\/code>\u72b6\u6001\u7684\u3002<\/p>\n<p>\u6211\u731c\u6d4b\u662fSafari\u6d4f\u89c8\u5668\u4e0d\u5e0c\u671b\u6309\u94ae\u6216\u94fe\u63a5\u70b9\u51fb\u7684\u65f6\u5019\u6709focus\u8f6e\u5ed3\u624d\u8fd9\u4e48\u8bbe\u8ba1\u7684\uff0c\u4f46\u662f\uff0c\u663e\u7136\u8fd9\u79cd\u4e00\u5200\u5207\u7684\u505a\u6cd5\u5c31\u4e0d\u5982Chrome\u548cFirefox\u6d4f\u89c8\u5668\u5904\u7406\u7684\u597d\uff0c\u5728Chrome\u6d4f\u89c8\u5668\u4e0b\uff0c\u9ed8\u8ba4\u72b6\u6001\u4e0b\uff0c\u6309\u94ae\u548c\u94fe\u63a5\u5728\u70b9\u51fb\u7684\u65f6\u5019\u662f\u4e0d\u4f1a\u6709<code>outline<\/code>\u8f6e\u5ed3\u7684\uff0c\u53ea\u6709\u952e\u76d8\u8bbf\u95ee\u7684\u65f6\u5019\u624d\u6709\uff0c\u517c\u987e\u89c6\u89c9\u548c\u65e0\u969c\u788d\u8bbf\u95ee\u3002<\/p>\n<p>\u90a3\u6709\u6ca1\u6709\u4ec0\u4e48\u529e\u6cd5\u8ba9Safari\u6d4f\u89c8\u5668\u4e0b\u7684\u94fe\u63a5\u548c\u6309\u94ae\u5728\u70b9\u51fb\u7684\u65f6\u5019\u4e5f\u80fd\u54cd\u5e94<code>:focus<\/code>\u4f2a\u7c7b\u5462\uff1f<\/p>\n<h4><code>&lt;a&gt;<\/code>\u94fe\u63a5focus<\/h4>\n<p>\u8981\u60f3\u8ba9Safari\u6d4f\u89c8\u5668\u4e0b<code>&lt;a&gt;<\/code>\u94fe\u63a5\u5143\u7d20\u5728\u70b9\u51fb\u540e\u4fdd\u6301focus\u72b6\u6001\uff0c\u53ef\u4ee5\u662f\u8bbe\u7f6e<code>tabindex=\"0\"<\/code>\uff0c\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n<pre>&lt;a href tabindex=\"0\"&gt;\u70b9\u51fb\u6211&lt;\/a&gt;<\/pre>\n<p><code>tabindex=\"0\"<\/code>\u4e0d\u4f1a\u5f71\u54cd\u94fe\u63a5\u5143\u7d20\u539f\u672c\u7684\u7d22\u5f15\u987a\u5e8f\uff0c\u5343\u4e07\u4e0d\u8981\u8bbe\u7f6e<code>tabindex<\/code>\u5c5e\u6027\u4e3a\u5176\u4ed6\u503c\uff0c\u5177\u4f53\u539f\u56e0\u8be6\u89c1\u6211\u5199\u7684\u8fd9\u7bc7\u6587\u7ae0\uff1a\u201c<a href=\"https:\/\/www.zhangxinxu.com\/wordpress\/2017\/05\/html-tabindex\/\">HTML tabindex\u5c5e\u6027\u4e0eweb\u7f51\u9875\u952e\u76d8\u65e0\u969c\u788d\u8bbf\u95ee<\/a>\u201d\u3002<\/p>\n<h4><code>&lt;button&gt;<\/code>\u6309\u94aefocus<\/h4>\n<p>\u8981\u60f3\u8ba9Safari\u6d4f\u89c8\u5668\u4e0b<code>&lt;button&gt;<\/code>\u6309\u94ae\u5143\u7d20\u5728\u70b9\u51fb\u540e\u4fdd\u6301focus\u72b6\u6001\uff0c\u76ee\u524d\u662f\u6ca1\u6709\u4ec0\u4e48\u6709\u6548\u65b9\u6cd5\u7684\u3002<\/p>\n<p><a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/HTML\/Element\/button\" rel=\"noopener\" target=\"_blank\">MDN\u6587\u6863<\/a>\u4e2d\u5bf9\u4e8e<code>&lt;button&gt;<\/code>\u6309\u94ae\u5143\u7d20\u7684\u70b9\u51fb\u548c\u805a\u7126\u7684\u5173\u7cfb\u6709\u4e13\u95e8\u7684\u6574\u7406\uff0c\u5177\u4f53\u53c2\u89c1\u4e0b\u8868\u3002<\/p>\n<style>td.bc-supports-no {    background-color: #f8e1e1;}<\/style>\n<table border=\"0\" width=\"100%\" class=\"params_table\" cellspacing=\"1\">\n<caption>\u662f\u5426\u70b9\u51fb\u6309\u94ae\u5143\u7d20\u53ef\u4ee5focus<\/caption>\n<thead>\n<tr>\n<th>\u684c\u9762\u6d4f\u89c8\u5668<\/th>\n<th>Windows 8.1<\/th>\n<th>OS X 10.X<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<th>Firefox<\/th>\n<td class=\"bc-supports-yes\">Yes &#8211; Firefox 30.0<\/td>\n<td class=\"bc-supports-no\">No (\u5373\u4f7f\u4f7f\u7528 <code>tabindex<\/code>) Firefox 63<\/td>\n<\/tr>\n<tr>\n<th>Chrome<\/th>\n<td class=\"bc-supports-yes\">Yes &#8211; Chrome 35<\/td>\n<td class=\"bc-supports-yes\">Yes &#8211; Chrome 65<\/td>\n<\/tr>\n<tr>\n<th>Safari<\/th>\n<td style=\"background: #eee;\">N\/A<\/td>\n<td class=\"bc-supports-no\">No (\u5373\u4f7f\u4f7f\u7528<code>tabindex<\/code>) Safari 12<\/td>\n<\/tr>\n<tr>\n<th>Internet Explorer<\/th>\n<td class=\"bc-supports-yes\">Yes &#8211; Internet Explorer 11<\/td>\n<td style=\"background: #eee;\">N\/A<\/td>\n<\/tr>\n<tr>\n<th>Presto<\/th>\n<td class=\"bc-supports-yes\">Yes &#8211; Opera 12<\/td>\n<td class=\"bc-supports-yes\">Yes &#8211; Opera 12<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<table border=\"0\" width=\"100%\" class=\"params_table\" cellspacing=\"1\">\n<caption>\u662f\u5426\u8f7b\u89e6\u6309\u94ae\u5143\u7d20\u53ef\u4ee5\u88abfocus<\/caption>\n<thead>\n<tr>\n<th>\u624b\u673a\u6d4f\u89c8\u5668<\/th>\n<th>iOS 7.1.2<\/th>\n<th>Android 4.4.4<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<th>Safari Mobile<\/th>\n<td class=\"bc-supports-no\">No (\u5373\u4f7f\u4f7f\u7528<code>tabindex<\/code>)<\/td>\n<td style=\"background-color: #eeeeee;\">N\/A<\/td>\n<\/tr>\n<tr>\n<th>Chrome 35<\/th>\n<td class=\"bc-supports-no\">No (even with a <code>tabindex<\/code>)<\/td>\n<td class=\"bc-supports-yes\">Yes<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u56e0\u6b64\uff0c\u5982\u679c\u5927\u5bb6\u8981\u4f7f\u7528<code>:focus-within<\/code>\u4f2a\u7c7b\uff0c\u540c\u65f6\u9700\u8981\u517c\u5bb9Safari\u6d4f\u89c8\u5668\uff0c\u8bf7\u4f7f\u7528<code>&lt;a&gt;<\/code>\u6807\u7b7e\u6309\u94ae\u4ee3\u66ff<code>&lt;button&gt;<\/code>\u6807\u7b7e\u6309\u94ae\u3002<\/p>\n<p><span class=\"hidden\">\/\/zxx: \u5982\u679c\u4f60\u770b\u5230\u8fd9\u6bb5\u6587\u5b57\uff0c\u8bf4\u660e\u4f60\u73b0\u5728\u8bbf\u95ee\u662f\u4f53\u9a8c\u7cdf\u7cd5\u7684\u5783\u573e\u76d7\u7248\u7f51\u7ad9\uff0c\u4f60\u53ef\u4ee5\u8bbf\u95ee\u539f\u6587\u83b7\u5f97\u5f88\u597d\u7684\u4f53\u9a8c\uff1ahttps:\/\/www.zhangxinxu.com\/wordpress\/?p=9621\uff08\u4f5c\u8005\u5f20\u946b\u65ed\uff09<\/span><\/p>\n<h3>\u4e8c\u3001focus\u65e0\u6cd5\u5931\u7126blur\u4e8b\u4ef6\u4e0d\u89e6\u53d1<\/h3>\n<p>\u4f8b\u5982\u5982\u4e0b\u4ee3\u7801\u6240\u793a\u7684<code>&lt;a&gt;<\/code>\u5143\u7d20\u518d\u70b9\u51fb\u4e4b\u540e\u4f1a\u88abfocus\uff0c\u4f46\u662f\u6b64\u65f6\u4f60\u518d\u70b9\u51fb\u9875\u9762\u7a7a\u767d\u533a\u57df\uff0c\u8be5\u5143\u7d20\u662f\u4e0d\u4f1a\u5931\u7126\u7684\uff0c\u4e5f\u5c31\u662f\u4e0d\u4f1ablur\u3002<\/p>\n<pre>&lt;a href tabindex=\"0\"&gt;\u70b9\u51fb\u6211&lt;\/a&gt;<\/pre>\n<p>\u8fd9\u4e2a\u73b0\u8c61\u53ea\u4f1a\u51fa\u73b0\u5728iOS Safari\u6d4f\u89c8\u5668\u4e0b\uff0c\u5fae\u4fe1\u548c\u539f\u751fSafari\u6d4f\u89c8\u5668\u90fd\u4f1a\u9047\u5230\u8fd9\u4e2a\u4f53\u9a8c\u95ee\u9898\u3002<\/p>\n<p>\u6211\u4e13\u95e8\u505a\u4e86\u4e2ademo\u6f14\u793a\u8fd9\u4e2a\u95ee\u9898\uff0c\u60a8\u53ef\u4ee5\u72e0\u72e0\u5730\u70b9\u51fb\u8fd9\u91cc\uff1a<a href=\"https:\/\/www.zhangxinxu.com\/study\/202010\/ios-safari-blur-demo.php\" rel=\"noopener\" target=\"_blank\">iOS Safari blur\u65e0\u6cd5\u89e6\u53d1demo<\/a><\/p>\n<p>\u6b64demo\u9700\u8981\u5728iOS Safari\u6d4f\u89c8\u5668\u4e0b\u8bbf\u95ee\uff0c\u56e0\u4e3a\u5982\u679c\u662fPC\u7535\u8111\uff0c\u53ef\u4ee5\u62ff\u51fa\u624b\u673a\u6253\u5f00\u5fae\u4fe1\u626b\u4e00\u626b\u8fdb\u884c\u4f53\u9a8c\uff1a<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/image.zhangxinxu.com\/image\/blog\/202010\/qrcode-demo-ios-safari-blur.png\" width=\"150\" height=\"150\" alt=\"demo\u9875\u9762\u4e8c\u7ef4\u7801\" class=\"aligncenter size-medium\" \/><\/p>\n<p>\u6b64\u65f6\uff0c\u70b9\u51fbdemo\u9875\u9762\u7684\u94fe\u63a5\uff08\u6709\u65f6\u5019\u9700\u8981\u70b9\u51fb2\u6b21\uff09\uff0c\u5c31\u4f1a\u770b\u5230\u4e0b\u62c9\u6d6e\u5c42\u51fa\u73b0\u4e86\uff0c\u5982\u4e0b\u622a\u56fe\u6240\u793a\uff1a<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/image.zhangxinxu.com\/image\/blog\/202010\/2020-10-26_002820.png\" width=\"298\" height=\"214\" alt=\"\u6d6e\u5c42\u51fa\u73b0\" class=\"alignnone size-medium\" \/><\/p>\n<p>\u76f8\u5173CSS\u4ee3\u7801\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n<pre>.drop-panel {\r\n    display: none;\r\n    position: absolute;    \r\n    border: 1px solid #ccc;\r\n    background-color: #fff;\r\n    padding: 12px 20px;\r\n}\r\n:focus + .drop-panel {\r\n    display: block;\r\n}<\/pre>\n<p>\u4f46\u662f\uff0c\u5728iPhone\u624b\u673a\u4e0b\uff0c\u6216\u8005iPad\u4e0b\uff0c\u6d6e\u5c42\u51fa\u73b0\u540e\uff0c\u4f60\u70b9\u51fb\u65c1\u8fb9\u767d\u8272\u7684\u7a7a\u767d\u533a\u57df\uff0c\u6d6e\u5c42\u6b7b\u6d3b\u90fd\u4e0d\u9690\u85cf\uff0c\u5bfc\u81f4<code>:focus<\/code>\u4f2a\u7c7b\u4ea4\u4e92\u5c31\u51fa\u73b0\u4e86\u95ee\u9898\u3002<\/p>\n<p>\u8fd9\u5c31\u662f\u8fd9\u4e00\u5c0f\u8282\u8981\u8bf4\u660e\u7684focus\u65e0\u6cd5\u5931\u7126blur\u4e8b\u4ef6\u4e0d\u89e6\u53d1\u7684\u95ee\u9898\u3002<\/p>\n<p><strong>\u8865\u5145\u4e8e\u7fcc\u65e5\uff1a<\/strong> \u4e0a\u9762blur\u4e0d\u89e6\u53d1\u6211\u5728iOS 12\u4e0b\u6d4b\u8bd5\u662f\u5b58\u5728\u7684\uff0c\u7136\u540e\u4eca\u5929\u6536\u5230\u53cd\u9988\uff0ciPhone 12\uff0ciOS 14\u70b9\u51fb\u7a7a\u767d\u5904\u53ef\u4ee5\u9690\u85cf\uff0c\u56e0\u6b64\uff0ciOS\u53ef\u80fd\u5728\u540e\u7eed\u7684\u7248\u672c\u4f18\u5316\u4e86\u8fd9\u4e2a\u4ea4\u4e92\u7ec6\u8282\u3002<\/p>\n<p>\u5b9e\u9645\u4e0a\uff0cblur\u5931\u7126\u662f\u53ef\u4ee5\u89e6\u53d1\u7684\uff0c\u5c31\u662f\u5f53\u6211\u4eec\u70b9\u51fb\u5176\u4ed6\u63a7\u4ef6\u5143\u7d20\u7684\u65f6\u5019\uff0c\u6bd4\u65b9\u8bf4\u6d6e\u5c42\u663e\u793a\u4e4b\u540e\uff0c\u6211\u4eec\u70b9\u51fb\u7684\u4e0d\u662f\u7a7a\u767d\u533a\u57df\uff0c\u800c\u662f\u6309\u94ae\u5143\u7d20\u3001\u6216\u8005\u662f\u5176\u4ed6\u94fe\u63a5\u5143\u7d20\uff0c\u6216\u8005\u8f93\u5165\u6846\u5143\u7d20\uff0c\u5219<code>:focus<\/code>\u4f1a\u5931\u7126\uff0cblur\u65f6\u95f4\u4f1a\u89e6\u53d1\uff0c\u4e5f\u5c31\u662f\u7126\u70b9\u4e0d\u80fd\u6d88\u5931\uff0c\u53ea\u80fd\u8f6c\u79fb\u3002<\/p>\n<p>\u6709\u6ca1\u6709\u4ec0\u4e48\u529e\u6cd5\u8ba9iOS Safari\u6d4f\u89c8\u5668\u4e0b\u7684\u53ef\u4ee5\u70b9\u51fb\u7a7a\u767d\u533a\u57df\u4e5f\u5931\u7126\u5462\uff1f<\/p>\n<p>\u53ef\u4ee5\u6709\u3002<\/p>\n<p>\u5c31\u662f\u627e\u5230\u5c42\u7ea7\u8db3\u591f\u9ad8\u7684\u7956\u5148\u5143\u7d20\uff08\u4e0d\u80fd\u662f<code>&lt;body&gt;<\/code>\u5143\u7d20\uff0c\u53ef\u4ee5\u662f<code>&lt;body&gt;<\/code>\u5b50\u5143\u7d20\uff09\uff0c\u7136\u540e\u8bbe\u7f6e<code>tabindex=-1<\/code>\uff0c\u4efb\u610f\u7684\u975e\u63a7\u4ef6HTML\u5143\u7d20\u5728\u8bbe\u7f6e\u4e86<code>tabindex=-1<\/code>\u5c5e\u6027\u540e\uff0c\u70b9\u51fb\u7684\u65f6\u5019\u662f\u4f1a\u6709focus\u72b6\u6001\u7684\u3002<\/p>\n<p>\u4e5f\u5c31\u662f\u70b9\u51fb\u7a7a\u767d\u533a\u57df\uff0c\u4f1a\u628a\u539f\u672c\u9644\u7740\u5728\u94fe\u63a5\u4e0a\u7684\u7126\u70b9\u8f6c\u79fb\u5230\u7956\u5148\u5143\u7d20\u4e0a\uff0c\u4e8e\u662fblur\u5931\u7126\u5c31\u6b63\u5e38\u89e6\u53d1\u4e86\u3002<\/p>\n<p>\u4f8b\u5982demo\u9875\u9762\u4e2d\u7684\u8fd9\u4e2a\u6309\u94ae\u70b9\u51fb\u540e\uff0c\u5c31\u4f1a\u7ed9\u4e00\u4e2a\u7956\u5148\u5143\u7d20\u8bbe\u7f6e<code>tabindex=-1<\/code>\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/image.zhangxinxu.com\/image\/blog\/202010\/2020-10-26_003615.png\" width=\"473\" height=\"243\" alt=\"\u70b9\u51fb\u7684\u6309\u94ae\u793a\u610f\" class=\"alignnone size-medium\" \/><\/p>\n<p>\u6b64\u65f6\u518d\u53bb\u70b9\u51fb\u4e0a\u9762\u7684\u94fe\u63a5\uff0c\u5c31\u4f1a\u53d1\u73b0\u6b64\u65f6\u70b9\u51fb\u9875\u9762\u7a7a\u767d\uff0c\u51fa\u73b0\u7684\u6d6e\u5c42\u6b63\u5e38\u6d88\u5931\u4e86\u3002<\/p>\n<h3>\u4e09\u3001focus()\u65b9\u6cd5\u6709\u65f6\u5019\u65e0\u6548<\/h3>\n<p>\u6709\u8fd9\u4e48\u4e00\u79cd\u4ea4\u4e92\u9700\u6c42\uff0c\u5c31\u662f\u70b9\u51fb\u67d0\u4e2a\u6309\u94ae\uff0c\u521b\u5efa\u4e86\u4e00\u4e2a\u65b0\u7684\u8f93\u5165\u6846\uff0c\u5e0c\u671b\u8fd9\u4e2a\u8f93\u5165\u6846\u5728\u521b\u5efa\u4e4b\u540e\u5c31\u7acb\u5373\u88abfocus\u547c\u8d77\u8f93\u5165\u8f6f\u952e\u76d8\u3002<\/p>\n<p>\u7136\u540e\u5728iOS Safari\u6d4f\u89c8\u5668\u4e0b\u6709\u65f6\u5019\u5c31\u4f1a\u51fa\u73b0 <code>input.focus()<\/code> \u65e0\u6548\u7684\u60c5\u51b5\u3002<\/p>\n<p>\u9996\u5148\u660e\u786e\u4e00\u70b9\uff0ciPhone\u6d4f\u89c8\u5668\u4e2d\u76f4\u63a5<code>input.focus()<\/code>\u662f\u53ef\u4ee5\u6709\u6548\u7684\uff0c\u4f46\u662f\u9700\u8981\u6709\u4e2a\u524d\u63d0\uff0c\u5c31\u662f\u5728\u70b9\u51fb\u4e8b\u4ef6\u4e2d\uff0c\u800c\u4e14\u662f\u8981\u5728\u70b9\u51fb\u4e8b\u4ef6\u8fd9\u4e2a\u7ebf\u7a0b\u4e2d\u3002<\/p>\n<p>\u4e5f\u5c31\u662f\u76f4\u63a5<code>input.focus()<\/code>\u662f\u65e0\u6cd5\u8ba9\u8f93\u5165\u6846focus\u7684\uff0c\u4f46\u662f\u5199\u5728click\u4e8b\u4ef6\u4e2d\u662f\u6709\u6548\u7684\uff0c\u4f8b\u5982\uff1a<\/p>\n<pre>button.addEventListener('click', function () {\r\n    <span style=\"color:green;\">\/\/ zhangxinxu: \u6709\u6548<\/span>\r\n    input.focus();\r\n});<\/pre>\n<p>\u6ce8\u610f\uff0c\u5e76\u4e0d\u662f\u8bf4<code>input.focus()<\/code>\u8bed\u53e5\u5199\u5728click\u4e8b\u4ef6\u4e2d\u5c31\u662f\u6709\u6548\u7684\u3002<\/p>\n<p>\u4f8b\u5982\u5728Vue\u7b49\u6846\u67b6\u4e2d\uff0cDOM\u7684\u6e32\u67d3\u662f\u6570\u636e\u9a71\u52a8\u7684\uff0c\u56e0\u6b64\uff0c\u5f80\u5f80\u4f1a\u5728click\u4e8b\u4ef6\u4e2d\u8fdb\u884c\u6570\u636e\u53d8\u5316\uff0c\u800c\u6b64\u65f6\u7684DOM\u6e32\u67d3\u5b9e\u5728click\u4e8b\u4ef6\u4e4b\u540e\u6267\u884c\u7684\uff0c\u56e0\u6b64\uff0c\u5f00\u53d1\u8005\u81ea\u7136\u800c\u7136\u4f1a\u60f3\u5230\u4f7f\u7528\u5b9a\u65f6\u5668\u8fdb\u884c\u5904\u7406\u3002<\/p>\n<p>\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n<pre>button.addEventListener('click', function () {\r\n    someDataChange();\r\n    <span style=\"color:red;\">\/\/ zhangxinxu: \u65e0\u6548<\/span>\r\n    setTimeout(function () {\r\n        input.focus();\r\n    }, 1);\r\n});<\/pre>\n<p>\u6b64\u65f6focus\u884c\u4e3a\u5c31\u4e0d\u4f1a\u89e6\u53d1\u662f\u65e0\u6548\u7684\uff0c\u56e0\u4e3a\u52a0\u4e86\u5b9a\u65f6\u5668\uff0cfocus\u884c\u4e3a\u5df2\u7ecf\u4e0d\u548cclick\u5728\u4e00\u4e2a\u6267\u884c\u7ebf\u7a0b\u4e2d\uff0c\u5904\u4e8e\u5b89\u5168\u548c\u4f53\u9a8c\u7684\u8003\u8651\uff0ciOS\u7cfb\u7edf\u5c31\u6ca1\u6709\u8ba9\u8f93\u5165\u6846focus\u805a\u7126\u3002<\/p>\n<p>\u77e5\u9053\u4e86\u539f\u56e0\u95ee\u9898\u5c31\u597d\u89e3\u51b3\u4e86\u3002<\/p>\n<p>\u6bd4\u65b9\u8bf4click\u4e8b\u4ef6\u66f4\u65b0\u7684\u662f\u662f\u5426focus\u7684\u6807\u5fd7\u91cf\uff0c\u7136\u540e\u5728Vue\u7684updated\u65b9\u6cd5\u4e2d\u8fdb\u884cfocus\u805a\u7126\uff0c\u4ee3\u7801\u793a\u610f\u5982\u4e0b\uff1a<\/p>\n<pre><span style=\"color:green;\">\/\/ \u65b0\u589e\u6570\u636e<\/span>\r\nthis.xxxData.push({\r\n  type: type,\r\n  content: 'zhangxinxu.com'\r\n})\r\n<span style=\"color:green;\">\/\/ \u6807\u5fd7\u91cf\u53d8\u5316<\/span>\r\ndocument.isFocusAfterUpdated = true<\/pre>\n<p><code>updated()<\/code>\u65b9\u6cd5\u4e2d\uff1a<\/p>\n<pre>if (document.isFocusAfterUpdated) {\r\n  input.focus()\r\n\r\n  <span style=\"color:green;\">\/\/ focus\u6807\u5fd7\u91cf\u8fd8\u539f<\/span>\r\n  document.isFocusAfterUpdated = false\r\n}<\/pre>\n<h3>\u56db\u3001\u5c0f\u7ed3\u4e00\u4e0b<\/h3>\n<p>\u6211\u76ee\u524d\u9047\u5230\u7684iOS Safari\u6d4f\u89c8\u5668\u4e0bfocus\u884c\u4e3a\u76f8\u5173\u7684\u201c\u5751\u7239\u201d\u884c\u4e3a\u67093\u4e2a\uff1a\u6309\u94ae\u5143\u7d20\u65e0\u6cd5\u88abfocus\u3001\u63a7\u4ef6\u5143\u7d20focus\u540e\u53ef\u80fd\u65e0\u6cd5\u5931\u7126\u4ee5\u53cafocus()\u805a\u7126\u53ef\u80fd\u65e0\u884c\u4e3a\u53d1\u751f\u3002<\/p>\n<p>\u6bcf\u4e2a\u95ee\u9898\u90fd\u63d0\u4f9b\u4e86\u76f8\u5173\u7684\u6307\u5bfc\u5efa\u8bae\u3002<\/p>\n<p>Safari\u53ef\u80fd\u8fd8\u6709\u5176\u4ed6\u548cfocus\u76f8\u5173\u7684\u5751\uff0c\u6b22\u8fce\u5927\u5bb6\u8865\u5145\u3002<\/p>\n<p>OK\uff0c\u4ee5\u4e0a\u5c31\u662f\u672c\u6587\u7684\u5168\u90e8\u5185\u5bb9\uff0c\u5e0c\u671b\u53ef\u4ee5\u5bf9\u4f60\u7684\u5de5\u4f5c\u6709\u6240\u5e2e\u52a9\u3002<\/p>\n<p>\u611f\u8c22\u9605\u8bfb\uff0c\u6b22\u8fce\u5206\u4eab\uff01<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"\/\/image.zhangxinxu.com\/image\/emtion\/emoji\/2764.svg\" width=\"20\" height=\"20\" align=\"absmiddle\"><\/p>\n<p>\u672c\u6587\u4e3a\u539f\u521b\u6587\u7ae0\uff0c\u6b22\u8fce\u5206\u4eab\uff0c\u52ff\u5168\u6587\u8f6c\u8f7d\uff0c\u5982\u679c\u5b9e\u5728\u559c\u6b22\uff0c\u53ef\u6536\u85cf\uff0c\u6c38\u4e0d\u8fc7\u671f\uff0c\u4e14\u4f1a\u53ca\u65f6\u66f4\u65b0\u77e5\u8bc6\u70b9\u53ca\u4fee\u6b63\u9519\u8bef\uff0c\u9605\u8bfb\u4f53\u9a8c\u4e5f\u66f4\u597d\u3002<br \/>\n\u672c\u6587\u5730\u5740\uff1a<a href=\"https:\/\/www.zhangxinxu.com\/wordpress\/?p=9621\">https:\/\/www.zhangxinxu.com\/wordpress\/?p=9621<\/a><\/p>\n<p>\uff08\u672c\u7bc7\u5b8c\uff09<\/p>\n","protected":false},"excerpt":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/image.zhangxinxu.com\/image\/blog\/202010\/iso-safari-focus-cover.png\" width=\"160\" height=\"102\" alt=\"\u5c01\u9762\u56fe\u5360\u4f4d\u56fe\" class=\"alignright size-medium\" loading=\"lazy\" \/><\/p>\n<p>iOS Safari\u6d4f\u89c8\u5668\u4e0b\u7684focus\u884c\u4e3a\u548c\u5176\u4ed6\u6d4f\u89c8\u5668\u90fd\u4e00\u4e9b\u660e\u663e\u4e0d\u4e00\u81f4\u7684\u5730\u65b9\uff0c\u6709\u65f6\u5019\u4f1a\u7ed9\u5f00\u53d1\u5e26\u6765\u56f0\u6270\uff0c\u8fd9\u91cc\u5c31\u8bf4\u8bf4\u76f8\u5173\u7684\u7ec6\u8282\u77e5\u8bc6\uff0c\u5747\u6e90\u81ea\u4e8e\u81ea\u5df1\u65e5\u5e38\u5f00\u53d1\uff0c\u5e0c\u671b\u53ef\u4ee5\u7ed9\u9047\u5230\u7c7b\u4f3c\u95ee\u9898\u7684\u524d\u7aef\u540c\u884c\u5e26\u6765\u5e2e\u52a9\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[648,7],"tags":[1209,547,887,422,295,908,148,138,784],"_links":{"self":[{"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/posts\/9621"}],"collection":[{"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/comments?post=9621"}],"version-history":[{"count":0,"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/posts\/9621\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/media?parent=9621"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/categories?post=9621"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/tags?post=9621"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}