{"id":52304,"date":"2024-12-03T17:07:21","date_gmt":"2024-12-03T09:07:21","guid":{"rendered":"https:\/\/fwq.ai\/blog\/52304\/"},"modified":"2024-12-03T17:07:21","modified_gmt":"2024-12-03T09:07:21","slug":"%e5%a6%82%e4%bd%95%e9%ab%98%e6%95%88%e5%9c%b0%e4%bd%bf-input-%e7%84%a6%e7%82%b9%e5%ae%9a%e4%bd%8d%e5%88%b0%e5%8f%b3%e4%be%a7%e6%9c%ab%e5%b0%be%ef%bc%9f-2","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/52304\/","title":{"rendered":"\u5982\u4f55\u9ad8\u6548\u5730\u4f7f Input \u7126\u70b9\u5b9a\u4f4d\u5230\u53f3\u4fa7\u672b\u5c3e\uff1f"},"content":{"rendered":"<p><b><\/b>     <\/p>\n<h1>\u5982\u4f55\u9ad8\u6548\u5730\u4f7f Input \u7126\u70b9\u5b9a\u4f4d\u5230\u53f3\u4fa7\u672b\u5c3e\uff1f <\/h1>\n<p>\u5728IT\u884c\u4e1a\u8fd9\u4e2a\u53d1\u5c55\u66f4\u65b0\u901f\u5ea6\u5f88\u5feb\u7684\u884c\u4e1a\uff0c\u53ea\u6709\u4e0d\u505c\u6b62\u7684\u5b66\u4e60\uff0c\u624d\u4e0d\u4f1a\u88ab\u884c\u4e1a\u6240\u6dd8\u6c70\u3002\u5982\u679c\u4f60\u662f\u6587\u7ae0\u5b66\u4e60\u8005\uff0c\u90a3\u4e48\u672c\u6587\u300a\u5982\u4f55\u9ad8\u6548\u5730\u4f7f Input \u7126\u70b9\u5b9a\u4f4d\u5230\u53f3\u4fa7\u672b\u5c3e\uff1f \u300b\u5c31\u5f88\u9002\u5408\u4f60\uff01\u672c\u7bc7\u5185\u5bb9\u4e3b\u8981\u5305\u62ec##content_title##\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\/20241119\/1732025742673c9d8eda1ab.jpg\" class=\"aligncenter\" title=\"\u5982\u4f55\u9ad8\u6548\u5730\u4f7f Input \u7126\u70b9\u5b9a\u4f4d\u5230\u53f3\u4fa7\u672b\u5c3e\uff1f\u63d2\u56fe\" alt=\"\u5982\u4f55\u9ad8\u6548\u5730\u4f7f Input \u7126\u70b9\u5b9a\u4f4d\u5230\u53f3\u4fa7\u672b\u5c3e\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u8282\u7701\u7cbe\u529b\u5730\u4e3a Input \u542f\u7528\u7126\u70b9\u5b9a\u4f4d\uff1f<\/strong><\/p>\n<p>\u5728\u9879\u76ee\u4e2d\u7ecf\u5e38\u9700\u8981\u5728\u83b7\u53d6 Input \u7126\u70b9\u65f6\u5c06\u5149\u6807\u7f6e\u4e8e\u53f3\u4fa7\u672b\u5c3e\uff0c\u4e00\u4e2a\u901a\u7528\u7684\u89e3\u51b3\u65b9\u6848\u53ef\u4ee5\u8282\u7701\u5927\u91cf\u7684\u4fee\u6539\u5de5\u4f5c\u3002<\/p>\n<p><strong>\u81ea\u5b9a\u4e49\u6307\u4ee4<\/strong><\/p>\n<p>\u6211\u4eec\u53ef\u4ee5\u5168\u5c40\u5b9a\u4e49\u4e00\u4e2a\u81ea\u5b9a\u4e49\u6307\u4ee4\u6765\u5b9e\u73b0\u8fd9\u4e00\u529f\u80fd\uff1a<\/p>\n<pre>Vue.directive('focus-right', {\n  inserted: function (el) {\n    el.addEventListener('focus', function () {\n      const length = el.value.length;\n      setTimeout(() =&gt; {\n        el.selectionStart = length;\n        el.selectionEnd = length;\n      });\n    });\n  }\n});<\/pre>\n<p>\u7136\u540e\u5728\u7ec4\u4ef6\u4e2d\u4f7f\u7528\uff1a<\/p>\n<pre>&lt;input v-focus-right&gt;<\/pre>\n<p><strong>\u63d2\u4ef6<\/strong><\/p>\n<p>\u4e5f\u53ef\u4ee5\u521b\u5efa\u4e00\u4e2a\u63d2\u4ef6\uff1a<\/p>\n<pre>const FocusRightPlugin = {\n  install(Vue) {\n    Vue.prototype.$inputFocusRight = function (e) {\n      const input = e.target;\n      const length = input.value.length;\n      setTimeout(() =&gt; {\n        input.selectionStart = length;\n        input.selectionEnd = length;\n      });\n    };\n  }\n};\n\n\/\/ \u5728 main.js \u4e2d\nimport FocusRightPlugin from '.\/focusPlugin';\n\nVue.use(FocusRightPlugin);\n\n\/\/ \u7ec4\u4ef6\u4e2d\u4f7f\u7528\n&lt;input @focus=\"$inputFocusRight\"&gt;<\/pre>\n<p>\u4eca\u5929\u5173\u4e8e\u300a\u5982\u4f55\u9ad8\u6548\u5730\u4f7f Input \u7126\u70b9\u5b9a\u4f4d\u5230\u53f3\u4fa7\u672b\u5c3e\uff1f \u300b\u7684\u5185\u5bb9\u4ecb\u7ecd\u5c31\u5230\u6b64\u7ed3\u675f\uff0c\u5982\u679c\u6709\u4ec0\u4e48\u7591\u95ee\u6216\u8005\u5efa\u8bae\uff0c\u53ef\u4ee5\u5728\u7c73\u4e91\u516c\u4f17\u53f7\u4e0b\u591a\u591a\u56de\u590d\u4ea4\u6d41\uff1b\u6587\u4e2d\u82e5\u6709\u4e0d\u6b63\u4e4b\u5904\uff0c\u4e5f\u5e0c\u671b\u56de\u590d\u7559\u8a00\u4ee5\u544a\u77e5\uff01<\/p>\n<dl>\n<dt><\/dt>\n<dd>\n   \u676d\u5dde\u82f9\u679c\u7b14\u8bb0\u672c\u7ef4\u4fee\u70b9\uff1f\n <\/dd>\n<\/dl>\n","protected":false},"excerpt":{"rendered":"<p>\u5982\u4f55\u9ad8\u6548\u5730\u4f7f Input \u7126\u70b9\u5b9a\u4f4d\u5230\u53f3\u4fa7\u672b\u5c3e\uff1f \u5728IT\u884c\u4e1a\u8fd9\u4e2a\u53d1\u5c55\u66f4\u65b0\u901f\u5ea6\u5f88\u5feb\u7684\u884c\u4e1a\uff0c\u53ea\u6709\u4e0d\u505c\u6b62\u7684\u5b66\u4e60\uff0c\u624d\u4e0d\u4f1a\u88ab\u884c\u4e1a\u6240\u6dd8\u6c70\u3002\u5982\u679c\u4f60\u662f\u6587\u7ae0\u5b66\u4e60\u8005\uff0c\u90a3\u4e48\u672c\u6587\u300a\u5982\u4f55\u9ad8\u6548\u5730\u4f7f Input \u7126\u70b9\u5b9a\u4f4d\u5230\u53f3\u4fa7\u672b\u5c3e\uff1f \u300b\u5c31\u5f88\u9002\u5408\u4f60\uff01\u672c\u7bc7\u5185\u5bb9\u4e3b\u8981\u5305\u62ec##content_title##\uff0c\u5e0c\u671b\u5bf9\u5927\u5bb6\u7684\u77e5\u8bc6\u79ef\u7d2f\u6709\u6240\u5e2e\u52a9\uff0c\u52a9\u529b\u5b9e\u6218\u5f00\u53d1\uff01 \u5982\u4f55\u8282\u7701\u7cbe\u529b\u5730\u4e3a Input \u542f\u7528\u7126\u70b9\u5b9a\u4f4d\uff1f \u5728\u9879\u76ee\u4e2d\u7ecf\u5e38\u9700\u8981\u5728\u83b7\u53d6 Input \u7126\u70b9\u65f6\u5c06\u5149\u6807\u7f6e\u4e8e\u53f3\u4fa7\u672b\u5c3e\uff0c\u4e00\u4e2a\u901a\u7528\u7684\u89e3\u51b3\u65b9\u6848\u53ef\u4ee5\u8282\u7701\u5927\u91cf\u7684\u4fee\u6539\u5de5\u4f5c\u3002 \u81ea\u5b9a\u4e49\u6307\u4ee4 \u6211\u4eec\u53ef\u4ee5\u5168\u5c40\u5b9a\u4e49\u4e00\u4e2a\u81ea\u5b9a\u4e49\u6307\u4ee4\u6765\u5b9e\u73b0\u8fd9\u4e00\u529f\u80fd\uff1a Vue.directive(&#8216;focus-right&#8217;, { inserted: function (el) { el.addEventListener(&#8216;focus&#8217;, function () { const length = el.value.length; setTimeout(() =&gt; { el.selectionStart = length; el.selectionEnd = length; }); }); } }); \u7136\u540e\u5728\u7ec4\u4ef6\u4e2d\u4f7f\u7528\uff1a &lt;input v-focus-right&gt; \u63d2\u4ef6 \u4e5f\u53ef\u4ee5\u521b\u5efa\u4e00\u4e2a\u63d2\u4ef6\uff1a const FocusRightPlugin = { install(Vue) { Vue.prototype.$inputFocusRight = [&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-52304","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/52304","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=52304"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/52304\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=52304"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=52304"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=52304"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}