{"id":52797,"date":"2024-12-03T11:25:08","date_gmt":"2024-12-03T03:25:08","guid":{"rendered":"https:\/\/fwq.ai\/blog\/52797\/"},"modified":"2024-12-03T11:25:08","modified_gmt":"2024-12-03T03:25:08","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-2","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/52797\/","title":{"rendered":"\u5982\u4f55\u786e\u4fdd\u591a\u4e2a\u8f93\u5165\u6846\u5fc5\u586b\u4e14\u6309\u987a\u5e8f\u586b\u5145\uff1f"},"content":{"rendered":"<p><b><\/b>     <\/p>\n<h1>\u5982\u4f55\u786e\u4fdd\u591a\u4e2a\u8f93\u5165\u6846\u5fc5\u586b\u4e14\u6309\u987a\u5e8f\u586b\u5145\uff1f<\/h1>\n<p>\u5927\u5bb6\u597d\uff0c\u6211\u4eec\u53c8\u89c1\u9762\u4e86\u554a~\u672c\u6587<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300a\u5982\u4f55\u786e\u4fdd\u591a\u4e2a\u8f93\u5165\u6846\u5fc5\u586b\u4e14\u6309\u987a\u5e8f\u586b\u5145\uff1f\u300b<\/span>\u7684\u5185\u5bb9\u4e2d\u5c06\u4f1a\u6d89\u53ca\u5230<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span>\u7b49\u7b49\u3002\u5982\u679c\u4f60\u6b63\u5728\u5b66\u4e60<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u6587\u7ae0<\/span>\u76f8\u5173\u77e5\u8bc6\uff0c\u6b22\u8fce\u5173\u6ce8\u6211\uff0c\u4ee5\u540e\u4f1a\u7ed9\u5927\u5bb6\u5e26\u6765\u66f4\u591a<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u6587\u7ae0<\/span>\u76f8\u5173\u6587\u7ae0\uff0c\u5e0c\u671b\u6211\u4eec\u80fd\u4e00\u8d77\u8fdb\u6b65\uff01\u4e0b\u9762\u5c31\u5f00\u59cb\u672c\u6587\u7684\u6b63\u5f0f\u5185\u5bb9~<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241123\/173234853167418a73cd138.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><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>\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>\u7ec8\u4e8e\u4ecb\u7ecd\u5b8c\u5566\uff01\u5c0f\u4f19\u4f34\u4eec\uff0c\u8fd9\u7bc7\u5173\u4e8e\u300a\u5982\u4f55\u786e\u4fdd\u591a\u4e2a\u8f93\u5165\u6846\u5fc5\u586b\u4e14\u6309\u987a\u5e8f\u586b\u5145\uff1f\u300b\u7684\u4ecb\u7ecd\u5e94\u8be5\u8ba9\u4f60\u6536\u83b7\u591a\u591a\u4e86\u5427\uff01\u6b22\u8fce\u5927\u5bb6\u6536\u85cf\u6216\u5206\u4eab\u7ed9\u66f4\u591a\u9700\u8981\u5b66\u4e60\u7684\u670b\u53cb\u5427~\u7c73\u4e91\u516c\u4f17\u53f7\u4e5f\u4f1a\u53d1\u5e03\u6587\u7ae0\u76f8\u5173\u77e5\u8bc6\uff0c\u5feb\u6765\u5173\u6ce8\u5427\uff01<\/p>\n<dl>\n<dt><\/dt>\n<dd>\n   \u4e24\u53f0\u7535\u8111\u4e92\u63d2\u7f51\u7ebf\u53ef\u4ee5\u4e0a\u7f51\u5417\uff1f\n <\/dd>\n<\/dl>\n","protected":false},"excerpt":{"rendered":"<p>\u5982\u4f55\u786e\u4fdd\u591a\u4e2a\u8f93\u5165\u6846\u5fc5\u586b\u4e14\u6309\u987a\u5e8f\u586b\u5145\uff1f \u5927\u5bb6\u597d\uff0c\u6211\u4eec\u53c8\u89c1\u9762\u4e86\u554a~\u672c\u6587\u300a\u5982\u4f55\u786e\u4fdd\u591a\u4e2a\u8f93\u5165\u6846\u5fc5\u586b\u4e14\u6309\u987a\u5e8f\u586b\u5145\uff1f\u300b\u7684\u5185\u5bb9\u4e2d\u5c06\u4f1a\u6d89\u53ca\u5230\u7b49\u7b49\u3002\u5982\u679c\u4f60\u6b63\u5728\u5b66\u4e60\u6587\u7ae0\u76f8\u5173\u77e5\u8bc6\uff0c\u6b22\u8fce\u5173\u6ce8\u6211\uff0c\u4ee5\u540e\u4f1a\u7ed9\u5927\u5bb6\u5e26\u6765\u66f4\u591a\u6587\u7ae0\u76f8\u5173\u6587\u7ae0\uff0c\u5e0c\u671b\u6211\u4eec\u80fd\u4e00\u8d77\u8fdb\u6b65\uff01\u4e0b\u9762\u5c31\u5f00\u59cb\u672c\u6587\u7684\u6b63\u5f0f\u5185\u5bb9~ \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; \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;); } \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 \u7ec8\u4e8e\u4ecb\u7ecd\u5b8c\u5566\uff01\u5c0f\u4f19\u4f34\u4eec\uff0c\u8fd9\u7bc7\u5173\u4e8e\u300a\u5982\u4f55\u786e\u4fdd\u591a\u4e2a\u8f93\u5165\u6846\u5fc5\u586b\u4e14\u6309\u987a\u5e8f\u586b\u5145\uff1f\u300b\u7684\u4ecb\u7ecd\u5e94\u8be5\u8ba9\u4f60\u6536\u83b7\u591a\u591a\u4e86\u5427\uff01\u6b22\u8fce\u5927\u5bb6\u6536\u85cf\u6216\u5206\u4eab\u7ed9\u66f4\u591a\u9700\u8981\u5b66\u4e60\u7684\u670b\u53cb\u5427~\u7c73\u4e91\u516c\u4f17\u53f7\u4e5f\u4f1a\u53d1\u5e03\u6587\u7ae0\u76f8\u5173\u77e5\u8bc6\uff0c\u5feb\u6765\u5173\u6ce8\u5427\uff01 \u4e24\u53f0\u7535\u8111\u4e92\u63d2\u7f51\u7ebf\u53ef\u4ee5\u4e0a\u7f51\u5417\uff1f<\/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-52797","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/52797","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=52797"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/52797\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=52797"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=52797"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=52797"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}