{"id":27861,"date":"2024-11-24T12:59:55","date_gmt":"2024-11-24T04:59:55","guid":{"rendered":"https:\/\/fwq.ai\/blog\/27861\/"},"modified":"2024-11-24T12:59:55","modified_gmt":"2024-11-24T04:59:55","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","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/27861\/","title":{"rendered":"\u5982\u4f55\u9ad8\u6548\u5730\u4f7f Input \u7126\u70b9\u5b9a\u4f4d\u5230\u53f3\u4fa7\u672b\u5c3e\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173132443864507.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>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u7136\u540e\u5728\u7ec4\u4ef6\u4e2d\u4f7f\u7528\uff1a<\/p>\n<pre>&lt;input v-focus-right&gt;<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\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>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5982\u4f55\u9ad8\u6548\u5730\u4f7f Input \u7126\u70b9\u5b9a\u4f4d\u5230\u53f3\u4fa7\u672b\u5c3e\uff1f\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\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; }); }); } }); \u767b\u5f55\u540e\u590d\u5236 \u7136\u540e\u5728\u7ec4\u4ef6\u4e2d\u4f7f\u7528\uff1a &lt;input v-focus-right&gt; \u767b\u5f55\u540e\u590d\u5236 \u63d2\u4ef6 \u4e5f\u53ef\u4ee5\u521b\u5efa\u4e00\u4e2a\u63d2\u4ef6\uff1a const FocusRightPlugin = { install(Vue) { Vue.prototype.$inputFocusRight = function (e) { const input [&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-27861","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/27861","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=27861"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/27861\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=27861"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=27861"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=27861"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}