{"id":3792,"date":"2024-11-10T13:53:28","date_gmt":"2024-11-10T05:53:28","guid":{"rendered":"https:\/\/fwq.ai\/blog\/3792\/"},"modified":"2024-11-10T13:53:28","modified_gmt":"2024-11-10T05:53:28","slug":"%e5%a6%82%e4%bd%95%e7%a1%ae%e4%bf%9d%e5%a4%9a%e4%b8%aa%e8%be%93%e5%85%a5%e6%a1%86%e5%bf%85%e5%a1%ab%e4%b8%94%e6%8c%89%e9%a1%ba%e5%ba%8f%e5%a1%ab%e5%85%85%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/3792\/","title":{"rendered":"\u5982\u4f55\u786e\u4fdd\u591a\u4e2a\u8f93\u5165\u6846\u5fc5\u586b\u4e14\u6309\u987a\u5e8f\u586b\u5145\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173114051312276.jpg\" class=\"aligncenter\" title=\"\u5982\u4f55\u786e\u4fdd\u591a\u4e2a\u8f93\u5165\u6846\u5fc5\u586b\u4e14\u6309\u987a\u5e8f\u586b\u5145\uff1f\u63d2\u56fe\" alt=\"\u5982\u4f55\u786e\u4fdd\u591a\u4e2a\u8f93\u5165\u6846\u5fc5\u586b\u4e14\u6309\u987a\u5e8f\u586b\u5145\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u786e\u4fdd\u8f93\u5165\u6846\u5fc5\u586b\u4e14\u6309\u987a\u5e8f\u586b\u5145<\/strong><\/p>\n<p>\u4e3a\u4e86\u786e\u4fdd\u591a\u4e2a\u8f93\u5165\u6846\u4e4b\u95f4\u4e0d\u80fd\u4e3a\u7a7a\u4e14\u5fc5\u987b\u4ece\u7b2c\u4e00\u4e2a\u8f93\u5165\u6846\u5f00\u59cb\u586b\u8d77\uff0c\u53ef\u4ee5\u91c7\u53d6\u4ee5\u4e0b\u6b65\u9aa4\uff1a<\/p>\n<p><strong>\u7ed9\u8f93\u5165\u6846\u6dfb\u52a0\u540d\u79f0\u5c5e\u6027<\/strong><\/p>\n<p>\u4e3a\u6bcf\u4e2a\u8f93\u5165\u6846\u5206\u914d\u4e00\u4e2a\u552f\u4e00\u7684\u540d\u79f0\u5c5e\u6027\uff0c\u4f8b\u5982\uff1a<\/p>\n<pre>&lt;input type=\"text\" name=\"input1\"&gt;\n&lt;input type=\"text\" name=\"input2\"&gt;\n&lt;input type=\"text\" name=\"input3\"&gt;<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p><strong>\u6dfb\u52a0\u4e8b\u4ef6\u76d1\u542c\u5668<\/strong><\/p>\n<p>\u5728\u6bcf\u4e2a\u8f93\u5165\u6846\u4e0a\u6dfb\u52a0\u4e00\u4e2a\u4e8b\u4ef6\u76d1\u542c\u5668\uff0c\u4f8b\u5982 blur \u6216 change\u3002\u5f53\u7126\u70b9\u79bb\u5f00\u6216\u5185\u5bb9\u53d1\u751f\u53d8\u5316\u65f6\u89e6\u53d1\u6b64\u4e8b\u4ef6\u76d1\u542c\u5668\u3002<\/p>\n<p><strong>\u5728\u4e8b\u4ef6\u76d1\u542c\u5668\u4e2d\u8fdb\u884c\u9a8c\u8bc1<\/strong><\/p>\n<p>\u5728\u4e8b\u4ef6\u76d1\u542c\u5668\u4e2d\uff0c\u6267\u884c\u4ee5\u4e0b\u64cd\u4f5c\uff1a<\/p>\n<ol>\n<li>\u83b7\u53d6\u5f53\u524d\u8f93\u5165\u6846\u7684\u540d\u79f0\u3002<\/li>\n<li>\u4f7f\u7528 previouselementsibling \u5c5e\u6027\u83b7\u53d6\u524d\u4e00\u4e2a\u8f93\u5165\u6846\u3002<\/li>\n<li>\u68c0\u67e5\u524d\u4e00\u4e2a\u8f93\u5165\u6846\u662f\u5426\u5177\u6709\u503c\u3002<\/li>\n<li>\u5982\u679c\u524d\u4e00\u4e2a\u8f93\u5165\u6846\u4e3a\u7a7a\uff0c\u5219\u963b\u6b62\u5f53\u524d\u8f93\u5165\u6846\u83b7\u53d6\u7126\u70b9\u6216\u8fdb\u884c\u4fee\u6539\u3002\u4f8b\u5982\uff0c\u53ef\u4ee5\u5728 input1 \u7684 blur \u4e8b\u4ef6\u76d1\u542c\u5668\u4e2d\u6dfb\u52a0\u4ee5\u4e0b\u4ee3\u7801\uff1a<\/li>\n<\/ol>\n<pre>const input2 = this.previousElementSibling;\nif (input2.value === \"\") {\n  this.blur();\n  alert(\"\u8bf7\u5148\u586b\u5199\u4e0a\u4e00\u4e2a\u8f93\u5165\u6846\u3002\");\n}<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u6b64\u4ee3\u7801\u68c0\u67e5 input1 \u7684\u524d\u4e00\u4e2a\u5143\u7d20 input2 \u662f\u5426\u4e3a\u7a7a\u3002\u5982\u679c\u662f\uff0c\u5b83\u5c06 input1 \u5931\u53bb\u7126\u70b9\uff0c\u5e76\u663e\u793a\u4e00\u4e2a\u8b66\u62a5\u6d88\u606f\u3002<\/p>\n<p>\u901a\u8fc7\u5b9e\u65bd\u8fd9\u4e9b\u6b65\u9aa4\uff0c\u53ef\u4ee5\u786e\u4fdd\u7528\u6237\u5fc5\u987b\u4ece\u7b2c\u4e00\u4e2a\u8f93\u5165\u6846\u5f00\u59cb\u586b\u5199\uff0c\u5e76\u4e14\u5728\u586b\u5199\u5b8c\u6240\u6709\u5fc5\u9700\u7684\u8f93\u5165\u6846\u4e4b\u524d\u65e0\u6cd5\u8fdb\u884c\u63d0\u4ea4\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5982\u4f55\u786e\u4fdd\u591a\u4e2a\u8f93\u5165\u6846\u5fc5\u586b\u4e14\u6309\u987a\u5e8f\u586b\u5145\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\u786e\u4fdd\u8f93\u5165\u6846\u5fc5\u586b\u4e14\u6309\u987a\u5e8f\u586b\u5145 \u4e3a\u4e86\u786e\u4fdd\u591a\u4e2a\u8f93\u5165\u6846\u4e4b\u95f4\u4e0d\u80fd\u4e3a\u7a7a\u4e14\u5fc5\u987b\u4ece\u7b2c\u4e00\u4e2a\u8f93\u5165\u6846\u5f00\u59cb\u586b\u8d77\uff0c\u53ef\u4ee5\u91c7\u53d6\u4ee5\u4e0b\u6b65\u9aa4\uff1a \u7ed9\u8f93\u5165\u6846\u6dfb\u52a0\u540d\u79f0\u5c5e\u6027 \u4e3a\u6bcf\u4e2a\u8f93\u5165\u6846\u5206\u914d\u4e00\u4e2a\u552f\u4e00\u7684\u540d\u79f0\u5c5e\u6027\uff0c\u4f8b\u5982\uff1a &lt;input type=&#8221;text&#8221; name=&#8221;input1&#8243;&gt; &lt;input type=&#8221;text&#8221; name=&#8221;input2&#8243;&gt; &lt;input type=&#8221;text&#8221; name=&#8221;input3&#8243;&gt; \u767b\u5f55\u540e\u590d\u5236 \u6dfb\u52a0\u4e8b\u4ef6\u76d1\u542c\u5668 \u5728\u6bcf\u4e2a\u8f93\u5165\u6846\u4e0a\u6dfb\u52a0\u4e00\u4e2a\u4e8b\u4ef6\u76d1\u542c\u5668\uff0c\u4f8b\u5982 blur \u6216 change\u3002\u5f53\u7126\u70b9\u79bb\u5f00\u6216\u5185\u5bb9\u53d1\u751f\u53d8\u5316\u65f6\u89e6\u53d1\u6b64\u4e8b\u4ef6\u76d1\u542c\u5668\u3002 \u5728\u4e8b\u4ef6\u76d1\u542c\u5668\u4e2d\u8fdb\u884c\u9a8c\u8bc1 \u5728\u4e8b\u4ef6\u76d1\u542c\u5668\u4e2d\uff0c\u6267\u884c\u4ee5\u4e0b\u64cd\u4f5c\uff1a \u83b7\u53d6\u5f53\u524d\u8f93\u5165\u6846\u7684\u540d\u79f0\u3002 \u4f7f\u7528 previouselementsibling \u5c5e\u6027\u83b7\u53d6\u524d\u4e00\u4e2a\u8f93\u5165\u6846\u3002 \u68c0\u67e5\u524d\u4e00\u4e2a\u8f93\u5165\u6846\u662f\u5426\u5177\u6709\u503c\u3002 \u5982\u679c\u524d\u4e00\u4e2a\u8f93\u5165\u6846\u4e3a\u7a7a\uff0c\u5219\u963b\u6b62\u5f53\u524d\u8f93\u5165\u6846\u83b7\u53d6\u7126\u70b9\u6216\u8fdb\u884c\u4fee\u6539\u3002\u4f8b\u5982\uff0c\u53ef\u4ee5\u5728 input1 \u7684 blur \u4e8b\u4ef6\u76d1\u542c\u5668\u4e2d\u6dfb\u52a0\u4ee5\u4e0b\u4ee3\u7801\uff1a const input2 = this.previousElementSibling; if (input2.value === &#8220;&#8221;) { this.blur(); alert(&#8220;\u8bf7\u5148\u586b\u5199\u4e0a\u4e00\u4e2a\u8f93\u5165\u6846\u3002&#8221;); } \u767b\u5f55\u540e\u590d\u5236 \u6b64\u4ee3\u7801\u68c0\u67e5 input1 \u7684\u524d\u4e00\u4e2a\u5143\u7d20 input2 \u662f\u5426\u4e3a\u7a7a\u3002\u5982\u679c\u662f\uff0c\u5b83\u5c06 input1 \u5931\u53bb\u7126\u70b9\uff0c\u5e76\u663e\u793a\u4e00\u4e2a\u8b66\u62a5\u6d88\u606f\u3002 \u901a\u8fc7\u5b9e\u65bd\u8fd9\u4e9b\u6b65\u9aa4\uff0c\u53ef\u4ee5\u786e\u4fdd\u7528\u6237\u5fc5\u987b\u4ece\u7b2c\u4e00\u4e2a\u8f93\u5165\u6846\u5f00\u59cb\u586b\u5199\uff0c\u5e76\u4e14\u5728\u586b\u5199\u5b8c\u6240\u6709\u5fc5\u9700\u7684\u8f93\u5165\u6846\u4e4b\u524d\u65e0\u6cd5\u8fdb\u884c\u63d0\u4ea4\u3002 \u4ee5\u4e0a\u5c31\u662f\u5982\u4f55\u786e\u4fdd\u591a\u4e2a\u8f93\u5165\u6846\u5fc5\u586b\u4e14\u6309\u987a\u5e8f\u586b\u5145\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},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-3792","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/3792","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=3792"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/3792\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=3792"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=3792"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=3792"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}