{"id":6335,"date":"2017-08-06T20:52:52","date_gmt":"2017-08-06T12:52:52","guid":{"rendered":"http:\/\/www.zhangxinxu.com\/wordpress\/?p=6335"},"modified":"2017-08-06T20:54:00","modified_gmt":"2017-08-06T12:54:00","slug":"html5-button-formaction-formenctype-formmethod-formtarget","status":"publish","type":"post","link":"https:\/\/www.zhangxinxu.com\/wordpress\/2017\/08\/html5-button-formaction-formenctype-formmethod-formtarget\/","title":{"rendered":"HTML5\u6309\u94ae\u5143\u7d20\u65b0\u5c5e\u6027formaction,formenctype\u7b49\u7b80\u4ecb"},"content":{"rendered":"<p>by <a href=\"http:\/\/www.zhangxinxu.com\/\">zhangxinxu<\/a> from <a href=\"http:\/\/www.zhangxinxu.com\/wordpress\/?p=6335\">http:\/\/www.zhangxinxu.com\/wordpress\/?p=6335<\/a><br \/>\n\u672c\u6587\u53ef\u5168\u6587\u8f6c\u8f7d\uff0c\u4f46\u9700\u5f97\u5230\u539f\u4f5c\u8005\u4e66\u9762\u8bb8\u53ef\uff0c\u540c\u65f6\u4fdd\u7559\u539f\u4f5c\u8005\u548c\u51fa\u5904\uff0c\u6458\u8981\u5f15\u6d41\u5219\u968f\u610f\u3002<\/p>\n<h3>\u4e00\u3001&lt;button&gt;\u7b49\u5143\u7d20\u65b0\u589eHTML5\u5c5e\u6027 &#8211; <code>form<\/code><\/h3>\n<p>\u5728\u8fc7\u53bb\uff0c\u8868\u5355\u5143\u7d20<code>&lt;form&gt;<\/code>\u548c\u8868\u5355\u63d0\u4ea4\u9700\u8981\u7684\u4e00\u4e9b\u63a7\u4ef6\u5143\u7d20\uff08\u5982<code>&lt;input&gt;<\/code>\uff0c<code>&lt;select&gt;<\/code>\uff09\u5728DOM\u7ed3\u6784\u4e0a\u5fc5\u987b\u662f\u7236\u5b50\u5173\u7cfb\uff0c\u4f46\u662f\u5728HTML5\u80cc\u666f\u4e0b\uff0c\u8868\u5355\u5143\u7d20\u548c\u63a7\u4ef6\u5143\u7d20\u53ef\u4ee5\u662f\u5728\u9875\u9762\u6587\u6863\u7684\u4efb\u4f55\u4f4d\u7f6e\uff0c\u8fd9\u79cd\u7279\u6027\u7684\u5b9e\u73b0\u5c31\u662f\u901a\u8fc7\u4f7f\u7528<code>form<\/code>\u5c5e\u6027\u3002<\/p>\n<p>\u5173\u4e8eHTML5\u65b0\u589e\u7684<code>form<\/code>\u5c5e\u6027\uff0c\u6211\u5728<a href=\"http:\/\/www.zhangxinxu.com\/wordpress\/?p=1715\">\u516d\u5e74\u524d\u5c31\u4ecb\u7ecd\u8fc7<\/a>\uff0c\u4e0d\u8fc7\u90a3\u7bc7\u6587\u7ae0\u662f\u4f7f\u7528<code>&lt;textarea&gt;<\/code>\u5143\u7d20\u793a\u610f\u7684\u3002<\/p>\n<p>\u60a8\u53ef\u4ee5\u72e0\u72e0\u5730\u70b9\u51fb\u8fd9\u91cc\uff1a<a target=\"_blank\" href=\"http:\/\/www.zhangxinxu.com\/study\/201106\/html5-new-form-attribute.html\">textarea\u793a\u610fform\u5c5e\u6027demo<\/a><\/p>\n<p>\u8fd9\u4e2ademo\u9875\u9762\u7684\u5173\u952eHTML\u4ee3\u7801\u5982\u4e0b\u793a\u610f\uff1a<\/p>\n<pre>&lt;form id=\"contact_form\" &gt;...&lt;\/form&gt;\n\u8bc4\u8bba\uff1a&lt;textarea id=\"comments\" name=\"comment\" form=\"contact_form\"&gt;&lt;\/textarea&gt;<\/pre>\n<p><code>&lt;textarea&gt;<\/code>\u5143\u7d20\u5728<code>&lt;form&gt;<\/code>\u5143\u7d20\u7684\u5916\u9762\uff0c\u800c\u4e0d\u662f\u7956\u5148\u548c\u540e\u4ee3\u7684\u5173\u7cfb\uff0c\u4f46\u662f\uff0c\u5f53\u6211\u4eec\u5728\u8868\u5355\u91cc\u9762\u586b\u5199\u6570\u636e\u5e76\u63d0\u4ea4\u7684\u65f6\u5019\uff0c\u4f1a\u53d1\u73b0<code>&lt;textarea&gt;<\/code>\u63a7\u4ef6\u4e2d\u7684\u6570\u636e\u4e00\u8d77\u63d0\u4ea4\u4e86\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/image.zhangxinxu.com\/image\/blog\/201708\/2017-08-06_173718.png\" width=\"288\" height=\"235\" alt=\"\u586b\u5199\u8868\u5355\u6570\u636e\u793a\u610f\" class=\"alignnone\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/image.zhangxinxu.com\/image\/blog\/201708\/2017-08-06_173752.png\" width=\"616\" height=\"54\" alt=\"URL\u5730\u5740\u4e2d\u6709textarea\u63d0\u4ea4\u7684\u6570\u636e\" class=\"alignnone\" \/><\/p>\n<p>\u5982\u679c<code>form<\/code>\u5c5e\u6027\u4f5c\u7528\u5728\u6309\u94ae\u4e0a\uff0c\u5c24\u5176\u662f\u5e26\u6709submit\u6027\u8d28\u7684\u8868\u5355\u63d0\u4ea4\u6309\u94ae\uff0c\u5219\u6700\u7ec8\u7684\u884c\u4e3a\u8868\u73b0\u662f\u53ef\u80fd\u5c31\u662f\u63d0\u4ea4\u53e6\u5916\u4e00\u4e2a<code>&lt;form&gt;<\/code>\u8868\u5355\u3002<\/p>\n<p>\u5b9e\u4f8b\u8bf4\u8bdd\uff0c\u60a8\u53ef\u4ee5\u72e0\u72e0\u5730\u70b9\u51fb\u8fd9\u91cc\uff1a<a href=\"http:\/\/www.zhangxinxu.com\/study\/201708\/button-form-submit-other-form.html\" target=\"_blank\">button\u6309\u94ae\u7684form\u63d0\u4ea4\u522b\u7684\u8868\u5355demo<\/a><\/p>\n<p>\u9875\u9762\u4e0a\u6709\u4e24\u4e2a\u8868\u5355\u5143\u7d20\uff0c\u63d0\u4ea4\u6309\u94ae\u5728\u7b2c\u4e8c\u4e2a\u8868\u5355\u5143\u7d20\u91cc\u9762\uff0c\u76f8\u5173HTML\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<pre>&lt;form id=\"form1\"&gt;\n    \u8868\u5355\u5e8f\u53f7\uff1a&lt;input name=\"formIndex\" value=\"1\" readonly&gt;\n&lt;\/form&gt;\n&lt;form id=\"form2\"&gt;\n    \u8868\u5355\u5e8f\u53f7\uff1a&lt;input name=\"formIndex\" value=\"2\" readonly&gt;\n    &lt;input type=\"submit\" value=\"\u63d0\u4ea4\" <span style=\"color:#cd0000;\">form=\"form1\"<\/span>&gt;\n&lt;\/form&gt;<\/pre>\n<p>\u7ed3\u679c\uff0c\u70b9\u51fb\u63d0\u4ea4\u6309\u94ae\uff0c\u63d0\u4ea4\u7684\u662f\u7b2c\u4e00\u4e2a\u8868\u5355\uff0c\u5982\u4e0b\u56fe\uff1a<br \/>\n<img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/image.zhangxinxu.com\/image\/blog\/201708\/2017-08-06_181232.png\" width=\"508\" height=\"328\" alt=\"\u63d0\u4ea4\u6309\u94ae\u63d0\u4ea4\u7684\u662f\u7b2c\u4e00\u4e2a\u8868\u5355\" class=\"alignnone\" \/><\/p>\n<p>\u6b64\u65f6\u63d0\u4ea4\u6309\u94ae\u4fe8\u7136\u53d8\u6210\u4e86\u4e00\u4e2a\u201c\u95f4\u8c0d\u201d\u3002<\/p>\n<h3>\u4e8c\u3001&lt;button&gt;\u5143\u7d20\u65b0\u589eHTML5\u5c5e\u6027 &#8211; formaction<\/h3>\n<p><code>formaction<\/code>\u5c5e\u6027\u53ea\u80fd\u4f5c\u7528\u4e8e\u5177\u6709\u63d0\u4ea4\u6027\u8d28\u7684\u6309\u94ae\uff08<code>type='submit'\/'image'<\/code>\uff09\u4e0a\uff0c\u4f5c\u7528\u548c\u540d\u79f0\u4e00\u6837\uff0c\u5982\u679c\u901a\u8fc7\u5f53\u524d\u6309\u94ae\u63d0\u4ea4\u8868\u5355\uff0c\u5728\u8868\u5355\u63d0\u4ea4\u5730\u5740\u4f1a\u4f7f\u7528<code>formaction<\/code>\u5c5e\u6027\u503c\u800c\u4e0d\u662f<code>form<\/code>\u5143\u7d20\u7684<code>action<\/code>\u5c5e\u6027\u503c\u3002<\/p>\n<p>\u4e3e\u4e2a\u7b80\u5355\u7684\u4f8b\u5b50\uff0c\u7eed\u7528\u4e0a\u9762\u7684\u6848\u4f8b\uff1a<\/p>\n<pre>&lt;form id=\"form1\"&gt;\n    \u8868\u5355\u5e8f\u53f7\uff1a&lt;input name=\"formIndex\" value=\"1\" readonly&gt;\n&lt;\/form&gt;\n&lt;form id=\"form2\"&gt;\n    \u8868\u5355\u5e8f\u53f7\uff1a&lt;input name=\"formIndex\" value=\"2\" readonly&gt;\n    &lt;input type=\"submit\" value=\"\u63d0\u4ea4\" form=\"form1\" <span style=\"color:#cd0000;\">formaction=\"blank.html\"<\/span>&gt;\n&lt;\/form&gt;<\/pre>\n<p>\u7ed3\u679c\uff0c\u70b9\u51fb\u63d0\u4ea4\u6309\u94ae\u540e\uff0c\u53bb\u5f80\u7684\u4e0d\u662f\u7684\u5f53\u524d\u9875\u4e86\uff0c\u800c\u662f\u540d\u4e3ablank.html\u7684\u9875\u9762\uff0c\u5728\u672c\u6f14\u793a\u4e2d\u662f\u4e00\u4e2a\u7a7a\u767d\u793a\u610f\u9875\u9762\uff0c\u6548\u679c\u5982\u4e0b\u56fe\uff1a<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/image.zhangxinxu.com\/image\/blog\/201708\/2017-08-06_183652.png\" width=\"563\" height=\"138\" alt=\"\u63d0\u4ea4\u5230\u7a7a\u767d\u9875\u793a\u610f\" class=\"alignnone\" \/><\/p>\n<p>\u773c\u89c1\u4e3a\u5b9e\uff0c\u60a8\u53ef\u4ee5\u72e0\u72e0\u7684\u70b9\u51fb\u8fd9\u91cc\uff1a<a href=\"http:\/\/www.zhangxinxu.com\/study\/201708\/button-formaction-submit-form.html\" target=\"_blank\">button\u6309\u94aeformaction\u5c5e\u6027\u91cd\u7f6e\u8868\u5355action demo<\/a><\/p>\n<p><strong>\u5982\u679c\u5f53\u524d\u8868\u5355\u4e0d\u662f\u901a\u8fc7\u63d0\u4ea4\u6309\u94ae\u63d0\u4ea4\uff1f<\/strong><br \/>\n\u8868\u5355\u63d0\u4ea4\uff0c\u4e0d\u4e00\u5b9a\u603b\u662f\u901a\u8fc7\u70b9\u51fb\u63d0\u4ea4\u6309\u94ae\uff0c\u8fd8\u53ef\u4ee5\u662f\u8f93\u5165\u6846\u56de\u8f66\u89e6\u53d1\uff0c\u4ea6\u6216\u8005\u662fJS <code>form.submit()<\/code>\uff0c\u5982\u679c\u662f\u8fd9\u7c7b\u63d0\u4ea4\uff0c\u90a3<code>formaction<\/code>\u5c5e\u6027\u8fd8\u6709\u6548\u5417\uff1f<\/p>\n<p>\u5982\u4e0b\u6d4b\u8bd5\u4ee3\u7801\uff1a<\/p>\n<pre>&lt;form&gt;\n    \u8868\u5355\u5e8f\u53f7\uff1a&lt;input name=\"formIndex\" value=\"1\"&gt;\uff08\u56de\u8f66\u8bd5\u8bd5\uff09\n    input type=\"button\" onClick=\"this.parentElement.parentElement.submit()\" value=\"JS\u89e6\u53d1\"&gt;\n    input type=\"submit\" value=\"\u63d0\u4ea4\" formaction=\"blank.html\"&gt;\n&lt;\/form&gt;<\/pre>\n<p>\u6d4b\u8bd5\u7ed3\u679c\u5982\u4e0b\uff1a<\/p>\n<ol>\n<li>\u8868\u5355\u56de\u8f66\u63d0\u4ea4\u7684\u65f6\u5019\uff0c<code>formaction<\/code>\u751f\u6548\u3002\u8fd9\u4e2a\u6bd4\u8f83\u597d\u7406\u89e3\uff0c\u4e00\u4e2a\u8868\u5355\uff0c\u8981\u60f3\u652f\u6301\u56de\u8f66\u4e8b\u4ef6\uff0c\u9700\u8981\u52a0\u5165\u4e00\u4e2asubmit\u6027\u8d28\u7684\u63d0\u4ea4\u6309\u94ae\u5c31\u53ef\u4ee5\uff0c\u5176\u4f5c\u7528\u672c\u8d28\u4e0a\u5c31\u662f\u56de\u8f66\u7684\u65f6\u5019\u70b9\u51fb\u4e86\u63d0\u4ea4\u6309\u94ae\uff08\u5982\u679c\u5728\u6309\u94ae\u4e0a\u8bbe\u7f6e<code>onClick=\"alert(0)\"<\/code>\uff0c\u56de\u8f66\u65f6\u5019\u4f1a\u6709\u5f39\u51fa\uff0c\u53ef\u4ee5\u8bc1\u660e\u8fd9\u4e00\u70b9\uff09\u3002<\/li>\n<li>\u5982\u679c\u662fJS <code>submit()<\/code>\u65b9\u6cd5\u89e6\u53d1\u7684\u63d0\u4ea4\uff0c\u5219<code>formaction<\/code>\u6ca1\u6709\u5bf9\u8868\u5355\u63d0\u4ea4\u7684<code>action<\/code>\u8fdb\u884c\u91cd\u7f6e\uff0c\u6d4b\u8bd5\u9875\u9762\u8868\u73b0\u4e3a\u63d0\u4ea4\u5230\u5f53\u524d\u9875\u9762\u3002<\/li>\n<\/ol>\n<p>\u773c\u89c1\u4e3a\u5b9e\uff0c\u60a8\u53ef\u4ee5\u72e0\u72e0\u7684\u70b9\u51fb\u8fd9\u91cc\uff1a<a href=\"http:\/\/www.zhangxinxu.com\/study\/201708\/button-formaction-in-form.html\" target=\"_blank\">\u6709formaction\u4f46\u8868\u5355\u975e\u6309\u94ae\u63d0\u4ea4\u6d4b\u8bd5demo<\/a><\/p>\n<p>\u501f\u52a9<code>formaction<\/code>\u5c5e\u6027\u53ef\u4ee5\u5b9e\u73b0\u4e00\u4e2a\u8868\u5355\u5185\u7684\u4e24\u4e2a\u6309\u94ae\u5206\u522b\u63d0\u4ea4\u5230\u4e0d\u540c\u5730\u5740\u7684\u6548\u679c\u3002<\/p>\n<h3>\u4e09\u3001&lt;button&gt;\u5143\u7d20\u65b0\u589eHTML5\u5c5e\u6027 &#8211; formenctype<\/h3>\n<p><code>formenctype<\/code>\u5c5e\u6027\u53ea\u80fd\u4f5c\u7528\u4e8e\u5177\u6709\u63d0\u4ea4\u6027\u8d28\u7684\u6309\u94ae\uff08<code>type='submit'\/'image'<\/code>\uff09\u4e0a\uff0c\u4f5c\u7528\u548c\u540d\u79f0\u4e00\u6837\uff0c\u5982\u679c\u901a\u8fc7\u5f53\u524d\u6309\u94ae\u63d0\u4ea4\u8868\u5355\uff0c\u5728\u8868\u5355\u63d0\u4ea4\u5730\u5740\u4f1a\u4f7f\u7528<code>formenctype<\/code>\u5c5e\u6027\u503c\u800c\u4e0d\u662f<code>form<\/code>\u5143\u7d20\u7684<code>enctype<\/code>\u5c5e\u6027\u503c\u3002<\/p>\n<p><code>form<\/code>\u5143\u7d20\u7684<code>enctype<\/code>\u5c5e\u6027\u53ef\u4ee5\u6307\u5b9a\u63d0\u4ea4\u6570\u636e\u7684\u7f16\u7801\u65b9\u5f0f\u3002<\/p>\n<ul>\n<li>\u9ed8\u8ba4\u4e3a<code>application\/x-www-form-urlencoded<\/code>\uff0c\u53ef\u4ee5\u7406\u89e3\u4e3a\u4ee5url\u683c\u5f0f\u5316\u89c4\u5219\u683c\u5f0f\u5316\uff08<code>%<\/code>\u5f00\u5934\u90a3\u4e9b\uff09\u7684\u5b57\u7b26\u4e32\u6570\u636e\uff1b<\/li>\n<li>\n<p>\u53ef\u4ee5\u8bbe\u7f6e\u4e3a<code>multipart\/form-data<\/code>\uff0c\u8fd9\u662fHTML5\u65b0\u589e\u7f16\u7801\u65b9\u5f0f\uff0c\u53ef\u4ee5\u7406\u89e3\u4e3a\u6240\u6709\u8868\u5355\u63d0\u4ea4\u6570\u636e\u4ee5\u4e8c\u8fdb\u5236\u5f62\u5f0f\u4f20\u8f93\uff0c\u4e8e\u662f\u6211\u4eec\u53ef\u4ee5Ajax\u76f4\u63a5\u4e0a\u4f20\u56fe\u7247\u7b49\u6587\u4ef6\u4fe1\u606f\u3002\u901a\u5e38\u5f53\u6709<code>type=\"file\"<\/code>\u7c7b\u578b\u7684<code>&lt;input&gt;<\/code><a href=\"http:\/\/www.zhangxinxu.com\/wordpress\/2015\/11\/html-input-type-file\/\">\u6587\u4ef6\u9009\u62e9\u6846<\/a>\u7684\u65f6\u5019\u624d\u4f7f\u7528\u3002<\/p>\n<\/li>\n<li>\u8fd8\u53ef\u4ee5\u662f<code>text\/plain<\/code>\uff0c\u8868\u793a\u7eaf\u6587\u672c\uff0c\u8fd9\u4e2a\u6211\u81ea\u5df1\u76ee\u524d\u5e76\u672a\u4f7f\u7528\u8fc7\uff0c\u5957\u8def\u4e0d\u8be6\u3002<\/li>\n<\/ul>\n<p>\u7531\u4e8e<code>formenctype<\/code>\u5c5e\u6027\u503c\u4e0d\u592a\u597d\u6d4b\u8bd5\uff0c\u56e0\u6b64\uff0c\u5c31\u4e0dshow demo\u4e86\u3002<\/p>\n<h3>\u56db\u3001&lt;button&gt;\u5143\u7d20\u65b0\u589eHTML5\u5c5e\u6027 &#8211; formmethod<\/h3>\n<p>\u7c7b\u4f3c\u7684\uff0c<code>formmethod<\/code>\u5c5e\u6027\u53ea\u80fd\u4f5c\u7528\u4e8e\u5177\u6709\u63d0\u4ea4\u6027\u8d28\u7684\u6309\u94ae\uff08<code>type='submit'\/'image'<\/code>\uff09\u4e0a\uff0c\u53ef\u4ee5\u8986\u76d6\u76ee\u6807<code>&lt;form&gt;<\/code>\u5143\u7d20\u7684<code>method<\/code>\u5c5e\u6027\u503c\uff08\u9ed8\u8ba4\u4e3a<code>get<\/code>\uff09\uff0c\u4f8b\u5982\uff1a<\/p>\n<pre>&lt;form id=\"form1\"&gt;\n    \u8868\u5355\u5e8f\u53f7\uff1a&lt;input name=\"formIndex\" value=\"1\" readonly&gt;\n&lt;\/form&gt;\n&lt;form id=\"form2\"&gt;\n    \u8868\u5355\u5e8f\u53f7\uff1a&lt;input name=\"formIndex\" value=\"2\" readonly&gt;\n    &lt;input type=\"submit\" value=\"\u63d0\u4ea4\" form=\"form1\" <span style=\"color:#cd0000;\">formmethod=\"post\"<\/span>&gt;\n&lt;\/form&gt;<\/pre>\n<p>\u6b64\u65f6\uff0c\u70b9\u51fb\u63d0\u4ea4\u6309\u94ae\u5c31\u662fPOST\u8868\u5355\uff0cURL\u5730\u5740\u540e\u9762\u6ca1\u6709\u51fa\u73b0\u67e5\u8be2\u5b57\u7b26\u4fe1\u606f\uff0c\u5982\u4e0b\u622a\u56fe\uff1a<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/image.zhangxinxu.com\/image\/blog\/201708\/2017-08-06_192111.png\" width=\"439\" height=\"280\" alt=\"POST\u8bf7\u6c42\u751f\u6548\u793a\u610f\" class=\"alignnone\" \/><\/p>\n<p>\u82e5\u6709\u5174\u8da3\uff0c\u53ef\u4ee5\u4eb2\u81ea\u70b9\u51fb\u611f\u53d7\u4e0b\uff0c\u60a8\u53ef\u4ee5\u72e0\u72e0\u7684\u70b9\u51fb\u8fd9\u91cc\uff1a<a href=\"http:\/\/www.zhangxinxu.com\/study\/201708\/button-formmethod-submit-form.html\" target=\"_blank\">button\u6309\u94aeformmethod\u5c5e\u6027\u91cd\u7f6edemo<\/a><\/p>\n<h3>\u4e94\u3001&lt;button&gt;\u5143\u7d20\u65b0\u589eHTML5\u5c5e\u6027 &#8211; formnovalidate<\/h3>\n<p><code>formnovalidate<\/code>\u662f\u4e00\u4e2a\u5e03\u5c14\u5c5e\u6027\u503c\uff0c\u53ea\u80fd\u4f5c\u7528\u4e8e\u5177\u6709\u63d0\u4ea4\u6027\u8d28\u7684\u6309\u94ae\uff08<code>type='submit'\/'image'<\/code>\uff09\u4e0a\uff0c\u53ef\u4ee5\u901a\u8fc7\u6b64\u6309\u94ae\u63d0\u4ea4\u7684\u8868\u5355\u4e0d\u8fdb\u884c\u539f\u751f\u7684\u6570\u636e\u9a8c\u8bc1\uff0c\u91cd\u7f6e\u7684\u662f<code>&lt;form&gt;<\/code>\u5143\u7d20\u7684<code>novalidate<\/code>\u5c5e\u6027\u3002<\/p>\n<h3>\u516d\u3001&lt;button&gt;\u5143\u7d20\u65b0\u589eHTML5\u5c5e\u6027 &#8211; formtarget<\/h3>\n<p>\u7c7b\u4f3c\u7684\uff0c<code>formtarget<\/code>\u5c5e\u6027\u53ea\u80fd\u4f5c\u7528\u4e8e\u5177\u6709\u63d0\u4ea4\u6027\u8d28\u7684\u6309\u94ae\uff08<code>type='submit'\/'image'<\/code>\uff09\u4e0a\uff0c\u53ef\u4ee5\u8986\u76d6\u76ee\u6807<code>&lt;form&gt;<\/code>\u5143\u7d20\u7684<code>target<\/code>\u5c5e\u6027\u503c\uff08\u9ed8\u8ba4\u4e3a<code>_self<\/code>\uff09\uff0c\u4f8b\u5982\uff1a<\/p>\n<pre>&lt;form&gt;\n    \u8868\u5355\u5e8f\u53f7\uff1a&lt;input name=\"formIndex\" value=\"1\" readonly&gt;\n    &lt;input type=\"submit\" value=\"\u63d0\u4ea4\" formaction=\"blank.html\" <span style=\"color:#cd0000;\">formtarget=\"_blank\"<\/span>&gt;\n&lt;\/form&gt;<\/pre>\n<p>\u6b64\u65f6\uff0cblank.html\u5c31\u5728\u6d4f\u89c8\u5668\u7684\u65b0\u7a97\u53e3\u6253\u5f00\u5566\uff01<\/p>\n<p>\u60a8\u53ef\u4ee5\u72e0\u72e0\u5730\u70b9\u51fb\u8fd9\u91cc\uff1a<a href=\"http:\/\/www.zhangxinxu.com\/study\/201708\/button-formtarget-submit-form.html\" target=\"_blank\">button\u6309\u94aeformtarget\u5c5e\u6027\u91cd\u7f6e\u8868\u5355target demo<\/a><\/p>\n<p>\u70b9\u51fb\u8fd9\u91cc\u7684\u6309\u94ae\u611f\u53d7\u4e0b\u5427~<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/image.zhangxinxu.com\/image\/blog\/201708\/2017-08-06_194540.png\" width=\"366\" height=\"228\" alt=\"\u70b9\u51fb\u63d0\u4ea4\u6309\u94ae\u65b0\u7a97\u53e3\u6253\u5f00blank.html\" class=\"alignnone\" \/><\/p>\n<p><strong>\u5c5e\u6027\u503c<\/strong><br \/>\n<code>formtarget<\/code>\u652f\u6301\u7684\u5c5e\u6027\u503c\u548c\u8868\u5355\u5143\u7d20\u7684<code>target<\/code>\u5c5e\u6027\u4e00\u6a21\u4e00\u6837\uff1a<\/p>\n<ul>\n<li><code>_self<\/code>\uff1a\u63d0\u4ea4\u4e8e\u5f53\u524d\u6d4f\u89c8\u5668\u4e0a\u4e0b\u6587\u3002\u9ed8\u8ba4\u503c\uff08\u5982\u679c\u4e0d\u8bbe\u7f6e\uff09\u3002<\/li>\n<li><code>_blank<\/code>\uff1a\u63d0\u4ea4\u4e8e\u65b0\u7684\u672a\u547d\u540d\u7684\u6d4f\u89c8\u5668\u4e0a\u4e0b\u6587\uff0c\u5728\u6d4f\u89c8\u5668\u4e2d\u7684\u8868\u73b0\u5c31\u662f\u65b0\u5f00\u6807\u7b7e\u9875\u3002<\/li>\n<li><code>_parent<\/code>\uff1a\u63d0\u4ea4\u4e8e\u7236\u7684\u6d4f\u89c8\u5668\u4e0a\u4e0b\u6587\uff0c\u5e38\u89c1\u4e8eiframe\u4e2d\uff0c\u5982\u679c\u6ca1\u6709\u7236\u7ea7\u6d4f\u89c8\u5668\u4e0a\u4e0b\u6587\uff0c\u5219\u6548\u679c\u7b49\u540c\u4e8e<code>_self<\/code>\u3002<\/li>\n<li><code>_top<\/code>\uff1a\u63d0\u4ea4\u4e8e\u9876\u7ea7\u6d4f\u89c8\u5668\u4e0a\u4e0b\u6587\uff08\u6700\u7956\u5148\u7684\u6d4f\u89c8\u5668\u4e0a\u4e0b\u6587\uff09\u3002\u5982\u679c\u6ca1\u6709\uff0c\u5219\u884c\u4e3a\u8868\u73b0\u7b49\u540c\u4e8e<code>_self<\/code>\u3002<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a~<\/p>\n<h3>\u4e03\u3001\u731d\u4e0d\u53ca\u9632\u7ed3\u675f\u8bed<\/h3>\n<p>\u672c\u6587\u4ecb\u7ecd\u7684<code>formaction<\/code>\uff0c<code>formtarget<\/code>\u7b49\u5c5e\u6027\u5b9e\u7528\u4ef7\u503c\u5728\u4e8e\uff0c\u53ef\u4ee5\u5bf9JS\u89e6\u53d1\u7684\u8868\u5355\u63d0\u4ea4\u548c\u70b9\u51fb\u56de\u8f66\u89e6\u53d1\u7684\u8868\u5355\u63d0\u4ea4\u5929\u7136\u533a\u5206\u5904\u7406\uff1b\u4ee5\u53ca\u5b9e\u73b0\u540c\u4e00\u4e2a\u8868\u5355\u5185\u63a7\u4ef6\u5143\u7d20\u7684\u4e0d\u540c\u884c\u4e3a\u5904\u7406\u3002<\/p>\n<p>\u4e3e\u4e2a\u4f8b\u5b50\uff1a<br \/>\n\u521b\u5efa\u4e00\u6761\u65b0\u6570\u636e\u57df\u4fee\u6539\u4e00\u6761\u6570\u636e\uff0c\u7528\u6237\u9700\u8981\u8f93\u5165\u7684\u5185\u5bb9\u51e0\u4e4e\u90fd\u662f\u4e00\u6a21\u4e00\u6837\u7684\uff0c\u8fd9\u610f\u5473\u65b0\u5efa\u7684\u8868\u5355\u548c\u4fee\u6539\u7684\u8868\u5355\u5176\u5b9e\u53ef\u4ee5\u5171\u7528\u7684\uff0c\u4f46\u5176\u4e2d\u5fc5\u7136\u8fd8\u662f\u6709\u4e00\u4e9b\u5dee\u5f02\u7684\uff0c\u4e3e\u4e2a\u4f8b\u5b50\uff0c\u65b0\u589e\u6570\u636e\u7684\u8868\u5355<code>action<\/code>\u5730\u5740\u53ef\u80fd\u662f<code>add.php<\/code>\uff0c\u800c\u4fee\u6539\u7684\u53ef\u80fd\u662f<code>edit.php<\/code>\u3002\u4ee5\u524d\u6211\u4eec\u505a\u6cd5\u53ef\u80fd\u662f\u6839\u636e\u573a\u666f\u4e0d\u540c\u4f7f\u7528JS\u53bb\u4fee\u6539<code>&lt;form&gt;<\/code>\u5143\u7d20\u7684<code>action<\/code>\uff0c\u540c\u65f6\u6539\u53d8\u63d0\u4ea4\u6309\u94ae\uff0c\u800c\u73b0\u5728\u5c11\u4e86\u4e00\u6b65\uff0c\u53ea\u9700\u8981\u63a7\u5236\u63d0\u4ea4\u6309\u94ae\u7684\u663e\u9690\u5c31\u53ef\u4ee5\u4e86\uff1a<\/p>\n<pre>&lt;form action=\"add.php\"&gt;\n  &lt;input type=\"submit\" value=\"\u65b0\u5efa\"&gt;\n  &lt;input type=\"submit\" value=\"\u4fee\u6539\" formaction=\"edit.php\"&gt;\n&lt;\/form&gt;<\/pre>\n<p>\u9664\u4e86\u5b9e\u73b0\u66f4\u7cbe\u7b80\uff0c\u6700\u5927\u7684\u597d\u5904\u662f\u66f4\u52a0\u8bed\u4e49\u5316\u4e86\u3002<\/p>\n<p>\u7528\u5f97\u5c11\u89c1\u5f97\u5c11\u4e0d\u4ee3\u8868\u6ca1\u6709\u7528\uff0c\u6316\u6398\u5176\u6f5c\u529b\uff0c\u53d1\u6325\u5176\u4ef7\u503c\uff0c\u7701\u65f6\u7701\u529b\u6548\u679c\u597d\u3002\u5728CSS\u548cHTML\u9886\u57df\u6709\u5f88\u591a\u4e0d\u663e\u5c71\u9732\u6c34\uff0c\u4f46\u7279\u6b8a\u573a\u666f\u975e\u5e38\u597d\u7528\u7684\u7279\u6027\u3002\u867d\u7136\u8fd9\u4e9b\u7279\u6027\u901a\u5e38\u90fd\u6709\u66ff\u4ee3\u65b9\u6848\uff08\u867d\u7136\u7a0d\u5fae\u5570\u55e6\u4e86\u70b9\uff09\uff0c\u597d\u50cf\u4e0d\u638c\u63e1\u4e5f\u6ca1\u4ec0\u4e48\u4e8b\uff0c\u52a0\u4e0a\u4e0d\u662f\u7ecf\u5e38\u4f7f\u7528\uff0c\u5b66\u4e60\u4e86\u4e0d\u80fd\u7acb\u5373\u4ea7\u80fd\uff0c\u56e0\u6b64\u5f88\u81ea\u7136\u89c9\u5f97\u6709\u8fd9\u4e2a\u95f2\u5de5\u592b\uff0c\u8fd8\u4e0d\u5982\u53bb\u5b66\u5b66\u4e00\u4e9b\u6bd4\u8f83\u6d41\u884c\u9ad8\u5927\u4e0a\u7684\u4e1c\u897f\u3002<\/p>\n<p>\u5b66\u4e60\u4e0d\u4e00\u5b9a\u6709\u5927\u7528\u5904\u7684\u57fa\u7840\u77e5\u8bc6\uff0c\u548c\u5b66\u4e60\u6d41\u884c\u7684\u4e0a\u5c42\u6536\u76ca\u8fc5\u901f\u7684\u4e8b\u7269\u5b9e\u9645\u4e0a\u662f\u4e24\u79cd\u4e0d\u540c\u7684\u6295\u8d44\uff0c\u4e00\u79cd\u662f\u4f4e\u98ce\u9669\u957f\u671f\u9ad8\u6536\u76ca\u7684\u957f\u671f\u6295\u8d44\uff0c\u4e00\u79cd\u662f\u9ad8\u98ce\u9669\u77ed\u671f\u6536\u76ca\u9ad8\u7684\u77ed\u671f\u6295\u8d44\u3002\u6bd4\u8f83\u5efa\u8bae\u7684\u6295\u8d44\u6bd4\u4f8b\u662f\u524d8\u540e2\uff0c\u4f46\uff0c\u4f46\u73b0\u5b9e\u4e16\u754c\u5e76\u4e0d\u662f\u8fd9\u6837\u5b50\u7684\uff0c\u6709\u592a\u591a\u592a\u591a\u4eba\uff0c\u5728\u884c\u60c5\u975e\u5e38\u597d\u7684\u65f6\u5019\uff0c\u4e0d\u60dc\u4e0b\u6760\u6746\u53bb\u98ce\u9669\u6bd4\u8f83\u9ad8\u7684\u80a1\u5e02\uff0c\u6b63\u5982\u73b0\u5728\u524d\u7aef\u5f62\u52bf\u6bd4\u8f83\u597d\u7684\u65f6\u5019\uff0c\u5168\u90e8\u7cbe\u529b\u90fd\u7528\u6765\u5b66\u4e60\u5404\u79cd\u5de5\u5177\u548c\u6846\u67b6\u4f7f\u7528\uff0c\u7ad9\u5728\u672a\u6765\u7684\u89d2\u5ea6\u770b\uff0c\u8fd9\u5176\u5b9e\u662f\u98ce\u9669\u76f8\u5f53\u9ad8\u7684\u4e00\u4ef6\u4e8b\u60c5\u3002<\/p>\n<p>\u5982\u679c\u518d\u8fdb\u4e00\u6b65\u6df1\u5165\u5206\u6790\uff0c\u6216\u8bb8\u5c31\u6d89\u53ca\u5230\u5b89\u5168\u611f\u7684\u95ee\u9898\u3002\u4f8b\u5982\u672c\u6587\u7684\u8fd9\u4e9b\u57fa\u7840\u77e5\u8bc6\uff0c\u7531\u4e8e\u4e0d\u786e\u5b9a\u6027\uff0c\u5047\u8bbe\u6211\u82b1\u4e861\u4e2a\u65f6\u95f4\u53bb\u4e86\u89e3\uff0c\u7ed3\u679c\u4e4b\u540e2\u5e74\u505a\u9879\u76ee\u90fd\u6ca1\u6709\u9047\u5230\u9002\u5408\u4f7f\u7528\u8fd9\u4e9b\u5c5e\u6027\u7684\u573a\u666f\uff0c\u90a3\u6211\u7684\u65f6\u95f4\u548c\u7cbe\u529b\u5c82\u4e0d\u662f\u767d\u767d\u7684\u6d6a\u8d39\u6389\u4e86\uff0c\u5f88\u5bb9\u6613\u5b89\u5168\u611f\u7f3a\u5931\u3002\u4f46\u662f\u5982\u679c\u6211\u53bb\u5b66\u4e60Vue\u4e4b\u7c7b\u7684\u6846\u67b6\uff0c\u7b80\u5386\u597d\u770b\u4e86\uff0c\u5de5\u4f5c\u597d\u627e\u4e86\uff0c\u4ed8\u51fa\u786e\u5b9a\u6709\u6536\u76ca\uff0c\u786e\u5b9a\u6027\u6548\u5e94\u8ba9\u4eba\u603b\u662f\u4e50\u4e8e\u505a\u8fd9\u6837\u7684\u4e8b\u60c5\u3002<\/p>\n<p>\u6240\u4ee5\uff0c\u867d\u7136\u6211\u591a\u6b21\u5728\u5404\u4e2a\u573a\u5408\u5f3a\u8c03\u57fa\u7840\u77e5\u8bc6\u7684\u91cd\u8981\u6027\uff0c\u4f46\u662f\u4eba\u6027\u672c\u8eab\u7684\u7279\u70b9\u4f7f\u5f97\u7edd\u5927\u591a\u6570\u4eba\u90fd\u65e0\u6cd5\u5728\u8fd9\u5757\u575a\u6301\u4e0b\u53bb\uff0c\u56e0\u4e3a\u5b66\u4e60\u4e00\u4e24\u4e2a\u57fa\u7840\u77e5\u8bc6\u771f\u7684\u662f\u4e00\u70b9\u7528\u90fd\u6ca1\u6709\uff0c\u4f60\u8981\u5b66\u4e60\u5f88\u591a\uff0c\u81f3\u5c11\u8981\u4e00\u4e24\u767e\u4e2a\uff0c\u624d\u6709\u8db3\u591f\u7684\u8986\u76d6\u7387\uff0c\u624d\u80fd\u6709\u4ece\u91cf\u53d8\u5230\u8d28\u53d8\u7684\u53d8\u5316\u3002<\/p>\n<p>\u4e0d\u8fc7\uff0c\u6362\u4e2a\u89d2\u5ea6\u60f3\uff0c\u8fd9\u6837\u5176\u5b9e\u4e5f\u597d\uff0c\u5927\u6d6a\u6dd8\u6c99\uff0c\u968f\u7740\u65f6\u95f4\u7684\u4e0d\u65ad\u63a8\u79fb\uff0c\u968f\u7740\u57fa\u7840\u7684\u4e0d\u65ad\u7d2f\u79ef\uff0c\u4ee5\u540e\u80fd\u548c\u81ea\u5df1\u7ade\u4e89\u7684\u4eba\u5c31\u8d8a\u6765\u8d8a\u5c11\u4e86\uff0c\u539a\u79ef\u8584\u53d1\uff0c\u9ad8\u5c4b\u5efa\u74f4\uff0c\u8d8a\u8001\u8d8a\u5403\u9999\uff0c\u6839\u672c\u4e0d\u7528\u62c5\u5fc3\u6240\u8c13\u7684\u4e2d\u5e74\u5371\u673a\uff0c\u6bd5\u7adf\u804c\u4e1a\u751f\u6daf40\u5e74\uff0c\u51e0\u4e4e\u6240\u6709\u7684IT\u4ece\u4e1a\u4eba\u5458\u624d\u521a\u5f00\u59cb\u5f00\u4e86\u4e2a\u5934\u3002<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/image.zhangxinxu.com\/image\/blog\/201611\/14.png\" align=\"absmiddle\"><\/p>\n<p>\u672c\u6587\u4e3a\u539f\u521b\u6587\u7ae0\uff0c\u4f1a\u7ecf\u5e38\u66f4\u65b0\u77e5\u8bc6\u70b9\u4ee5\u53ca\u4fee\u6b63\u4e00\u4e9b\u9519\u8bef\uff0c\u56e0\u6b64\u8f6c\u8f7d\u8bf7\u4fdd\u7559\u539f\u51fa\u5904\uff0c\u65b9\u4fbf\u6eaf\u6e90\uff0c\u907f\u514d\u9648\u65e7\u9519\u8bef\u77e5\u8bc6\u7684\u8bef\u5bfc\uff0c\u540c\u65f6\u6709\u66f4\u597d\u7684\u9605\u8bfb\u4f53\u9a8c\u3002<br \/>\n\u672c\u6587\u5730\u5740\uff1a<a href=\"http:\/\/www.zhangxinxu.com\/wordpress\/?p=6335\">http:\/\/www.zhangxinxu.com\/wordpress\/?p=6335<\/a><\/p>\n<p>\uff08\u672c\u7bc7\u5b8c\uff09<\/p>\n","protected":false},"excerpt":{"rendered":"<p>HTML5\u8868\u5355\u63d0\u4ea4\u6309\u94ae\u65b0\u589e\u52a0\u4e86<code>formaction<\/code>, <code>formenctype<\/code>\u7b49\u5c5e\u6027\uff0c\u8fd9\u4e9b\u5c5e\u6027\u662f\u4ec0\u4e48\u610f\u601d\uff1f\u6709\u4ec0\u4e48\u4f5c\u7528\uff1f\u672c\u6587\u5c31\u5c06\u901a\u8fc7\u4e00\u4e2a\u4e2a\u7684\u6848\u4f8b\u5e26\u9886\u5927\u5bb6\u53bb\u8ba4\u8bc6\u8fd9\u4e9b\u5c5e\u6027\uff08\u51716\u4e2a\uff09\uff0c\u4ee5\u53ca\u5728\u5b9e\u9645\u5f00\u53d1\u4e2d\u7684\u4e00\u4e9b\u5e94\u7528\uff0c\u5e0c\u671b\u80fd\u591f\u5bf9\u8bf8\u4f4d\u7684\u65e5\u5e38\u5f00\u53d1\u6709\u6240\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":[1097],"tags":[422,607,1157,1160,1158,1159,188,709],"_links":{"self":[{"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/posts\/6335"}],"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=6335"}],"version-history":[{"count":0,"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/posts\/6335\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/media?parent=6335"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/categories?post=6335"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/tags?post=6335"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}