{"id":126403,"date":"2020-05-11T21:15:02","date_gmt":"2020-05-11T13:15:02","guid":{"rendered":"http:\/\/4563.org\/?p=126403"},"modified":"2020-05-11T21:15:02","modified_gmt":"2020-05-11T13:15:02","slug":"%e5%a6%82%e4%bd%95%e7%94%a8-javascript-%e8%8e%b7%e5%8f%96%e8%ae%ba%e5%9d%9b%e3%80%81%e5%8d%9a%e5%ae%a2%e7%ad%89%e4%b8%8d%e5%90%8c%e7%bd%91%e7%ab%99%e5%85%89%e6%a0%87%e6%89%80%e5%9c%a8%e7%9a%84-form","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=126403","title":{"rendered":"\u5982\u4f55\u7528 JavaScript \u83b7\u53d6\u8bba\u575b\u3001\u535a\u5ba2\u7b49\u4e0d\u540c\u7f51\u7ad9\u5149\u6807\u6240\u5728\u7684 form \u5143\u7d20\u8c03\u7528 submit()"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  \u5982\u4f55\u7528 JavaScript \u83b7\u53d6\u8bba\u575b\u3001\u535a\u5ba2\u7b49\u4e0d\u540c\u7f51\u7ad9\u5149\u6807\u6240\u5728\u7684 form \u5143\u7d20\u8c03\u7528 submit()               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : soooulp <\/span>  <span><i><\/i> 10<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\"> <\/p>\n<p>\u60f3\u901a\u8fc7 JavaScript\uff0c\u83b7\u53d6\u8bba\u575b\u3001\u535a\u5ba2\u7b49\u4e0d\u540c\u7f51\u7ad9\u5149\u6807\u6240\u5728\u5f53\u524d form\uff0c\u8c03\u7528 submit() \uff0c\u6267\u884c input \u6216\u8005 textarea \u8f93\u5165\u6846\u4e3a type=&#8221;submit&#8221;\u7684\u63d0\u4ea4\uff0c\u4e0d\u518d\u70b9\u6309\u94ae\u548c\u6309 enter<\/p>\n<p>\u73b0\u5728\u6ca1\u529e\u6cd5\u8bc6\u522b\u4e0d\u540c\u7f51\u7ad9\u5149\u6807\u6240\u5728\u7684 input \u6216 textarea \u7684 form \u5143\u7d20<\/p>\n<p>\u5c1d\u8bd5\u4e86\u4e0b\u9762\u7684\u65b9\u6cd5\uff0c\u5c31\u767e\u5ea6\u7684\u6709\u6548\u679c\uff0c\u8bba\u575b\u6309 ctrl+enter \u4e0d\u80fd\u63d0\u4ea4\u7684 textarea \u8f93\u5165\u6846\u6ca1\u6548\u679c\uff0c\u518d\u6709\u4e9b\u8bba\u575b\u4e0d\u80fd\u786e\u5b9a\u56de\u590d\u6587\u672c\u6846\u7684\u5e8f\u53f7\uff0c\u4f1a\u6267\u884c\u641c\u7d22\u8f93\u5165\u6846\uff0c\u5373\u7b2c\u4e00\u4e2a form<br \/> \u4e0d\u540c\u7f51\u7ad9 form \u7684 name \u4e0d\u4e00\u6837\uff0c\u4e5f\u4e0d\u80fd\u901a\u8fc7 form[<code>name<\/code>]\u8c03\u7528<\/p>\n<pre><code>document.forms[0].submit() <\/code><\/pre>\n<p>\u5c1d\u8bd5\u4e86\u7528\u4e0b\u9762\u7684\u65b9\u6cd5\uff0c\u6ca1\u6709\u6548\u679c<\/p>\n<pre><code>this.submit() <\/code><\/pre>\n<\/p><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>6<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li data-pid=\"2014053\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : autoxbc <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             document.activeElement<br \/>https:\/\/www.runoob.com\/jsref\/prop-document-activeelement.html                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"2014054\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : soooulp <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @autoxbc \u8c22\u8c22\u5927\u4f6c\u56de\u590d\uff0cdocument.activeElement \u53ef\u4ee5\u83b7\u53d6\u5f53\u524d DOM \u7684\u5143\u7d20\uff0c\u53ef\u662f\u65e0\u6cd5\u8c03\u7528 submit \u63d0\u4ea4\u5440\uff0c\u662f\u4e0d\u662f\u53ea\u6709 form \u53ef\u4ee5\u8c03\u7528                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"2014055\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : autoxbc <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             HTMLFormElement.prototype.submit<br \/>submit \u662f form \u539f\u578b\u5bf9\u8c61\u4e0a\u7684\u65b9\u6cd5\uff0c\u53ea\u6709 form \u5b9e\u4f8b\u624d\u53ef\u4ee5 submit\uff0c\u56e0\u4e3a submit \u9700\u8981\u7684\u5730\u5740 action \u5728 form \u4e0a\uff0c\u5355\u72ec\u7684 input \u53bb submit \u672c\u8eab\u4e5f\u4e0d\u5408\u903b\u8f91<\/p>\n<p>HTMLInputElement.prototype.form<br \/>input \u539f\u578b\u5bf9\u8c61\u4e0a\u6709 getter \u5c5e\u6027 form\uff0c\u6307\u5411 input \u6240\u5c5e form\uff0c\u6240\u4ee5\u6309\u7167\u9898\u76ee\u7684\u610f\u601d\uff0c\u53ef\u4ee5 input.form.submit()                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"2014056\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : autoxbc <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             HTMLTextAreaElement.prototype.form<br \/>textarea \u4e5f\u6709\u8fd9\u4e2a\u5c5e\u6027                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"2014057\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : soooulp <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u89e3\u51b3\u4e86\uff0ccsdn \u5927\u4f6c\u7ed9\u6709\u4e2a\u904d\u5386\u8282\u70b9\u5143\u7d20\u7684\u65b9\u6cd5<\/p>\n<p>&#8220;`<br \/>function getParentFormByChild(ele){<br \/> while(ele.parentNode.tagName.toLowerCase() !== &#8216;body&#8217; &amp;&amp; ele.parentNode.tagName.toLowerCase() !== &#8216;form&#8217;){<br \/> ele = ele.parentNode<br \/> }<br \/> if(ele.parentNode.tagName.toLowerCase() === &#8216;body&#8217; ) return null<br \/> return ele.parentNode<br \/>}<\/p>\n<p>function \u6cb9\u7334\u5b50\u70b9\u51fb\u56fe\u6807\u4e8b\u4ef6(){<br \/> let ele = &#8220;\u6cb9\u7334\u5b50\u83b7\u53d6\u5f53\u524d\u5149\u6807\u6240\u5728 input \u7684 dom \u5143\u7d20&#8221;<br \/> let fromEle = getParentFormByChild(ele)<br \/> if(fromEle) fromEle.submit()<br \/>}<br \/>&#8220;`                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"2014058\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : soooulp <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @autoxbc \u518d\u6b21\u8c22\u8c22\u4f20\u6388                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>\u5982\u4f55\u7528 JavaScript \u83b7\u53d6&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[],"_links":{"self":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/126403"}],"collection":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=126403"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/126403\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=126403"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=126403"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=126403"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}