久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

  • <small id='QtjVF'></small><noframes id='QtjVF'>

    <legend id='QtjVF'><style id='QtjVF'><dir id='QtjVF'><q id='QtjVF'></q></dir></style></legend>
      <bdo id='QtjVF'></bdo><ul id='QtjVF'></ul>

    1. <i id='QtjVF'><tr id='QtjVF'><dt id='QtjVF'><q id='QtjVF'><span id='QtjVF'><b id='QtjVF'><form id='QtjVF'><ins id='QtjVF'></ins><ul id='QtjVF'></ul><sub id='QtjVF'></sub></form><legend id='QtjVF'></legend><bdo id='QtjVF'><pre id='QtjVF'><center id='QtjVF'></center></pre></bdo></b><th id='QtjVF'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='QtjVF'><tfoot id='QtjVF'></tfoot><dl id='QtjVF'><fieldset id='QtjVF'></fieldset></dl></div>
    2. <tfoot id='QtjVF'></tfoot>

        使用 submit() 從鏈接提交的表單無法被 onsubmit 處理

        Form submitted using submit() from a link cannot be caught by onsubmit handler(使用 submit() 從鏈接提交的表單無法被 onsubmit 處理程序捕獲)

          • <bdo id='rkhcl'></bdo><ul id='rkhcl'></ul>

              <tbody id='rkhcl'></tbody>
              <i id='rkhcl'><tr id='rkhcl'><dt id='rkhcl'><q id='rkhcl'><span id='rkhcl'><b id='rkhcl'><form id='rkhcl'><ins id='rkhcl'></ins><ul id='rkhcl'></ul><sub id='rkhcl'></sub></form><legend id='rkhcl'></legend><bdo id='rkhcl'><pre id='rkhcl'><center id='rkhcl'></center></pre></bdo></b><th id='rkhcl'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='rkhcl'><tfoot id='rkhcl'></tfoot><dl id='rkhcl'><fieldset id='rkhcl'></fieldset></dl></div>

                <tfoot id='rkhcl'></tfoot>
                • <small id='rkhcl'></small><noframes id='rkhcl'>

                • <legend id='rkhcl'><style id='rkhcl'><dir id='rkhcl'><q id='rkhcl'></q></dir></style></legend>
                  本文介紹了使用 submit() 從鏈接提交的表單無法被 onsubmit 處理程序捕獲的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  很驚訝,我在從 JS 提交表單時遇到了這個奇怪的問題.

                  Surprised, I am encountering this weird issue while submitting form from JS.

                  考慮一個使用 submit 按鈕和 anchor link

                  Consider a simple form submitted using two ways from a submit button and an anchor link

                  <form method="POST" action="page.html" name="foobar" id="test">
                    <input type="text" />
                    <input type="submit" />
                  </form>
                  
                  <a href="#" onclick="document.getElementById('test').submit();">click me</a>
                  

                  捕獲提交事件的函數

                  document.getElementById('test').onsubmit = function() {
                     // Same result with 
                     //     * document.foobar.onsubmit
                     //     * document.forms['foobar'].onsubmit
                  
                     alert('foobar');
                     return false;
                  }
                  

                  現在,當通過單擊 submit 按鈕提交表單時,我會收到警報,但 單擊鏈接時不會.為什么會這樣?

                  Now, when the form is submitted from clicking the submit button I get the alert, but not when clicking the link. Why is this doing so?

                  小提琴顯示問題

                  推薦答案

                  為了提供一個合理確定的答案,HTML 表單提交算法 第 5 項指出,表單僅在未提交時才調度提交事件通過調用提交方法(這意味著它僅在通過按鈕或其他隱式方法提交時才調度提交事件,例如在焦點位于輸入類型文本元素上時按 Enter).

                  To provide a reasonably definitive answer, the HTML Form Submission Algorithm item 5 states that a form only dispatches a submit event if it was not submitted by calling the submit method (which means it only dispatches a submit event if submitted by a button or other implicit method, e.g. pressing enter while focus is on an input type text element).

                  如果沒有發送提交事件,則不會調用提交處理程序.

                  If no submit event is dispatched, then the submit handler won't be called.

                  這與 DOM 2 HTML 不同規范,它說提交方法應該做提交按鈕所做的事情.

                  That is different to the DOM 2 HTML specification, which said that the submit method should do what the submit button does.

                  所以如果你想使用腳本提交表單,你應該手動調用提交監聽器.如果偵聽器是使用 addEventListener 添加的,那么您需要記住并調用它,因為您無法通過檢查表單來發現它(如下所示).

                  So if you want to use script to submit a form, you should manually call the submit listener. If the listener was added using addEventListener, then you'll need to remember that and to call it since you can't discover it by inspecting the form (as suggested below).

                  如果監聽器是內聯設置的,或者添加到 DOM onsubmit 屬性中,你可以這樣做:

                  If the listener is set inline, or added to the DOM onsubmit property, you can do something like:

                  <form onsubmit="return validate(this);" ...>
                    ...
                  </form>
                  <button onclick="doSubmit()">submit form</button>
                  
                  <script>
                  function doSubmit() {
                    var form = document.forms[0];
                  
                    if (form.onsubmit) {
                      var result = form.onsubmit.call(form);
                    }
                  
                    if (result !== false) {
                      form.submit();
                    }
                  }
                  </script>
                  

                  如果您需要傳遞參數或做其他事情,生活會更加艱難.

                  Life is tougher if you need to pass parameters or do other things.

                  這篇關于使用 submit() 從鏈接提交的表單無法被 onsubmit 處理程序捕獲的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                  【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                  相關文檔推薦

                  Use IScroll in Angular 2 / Typescript(在 Angular 2/Typescript 中使用 IScroll)
                  anime.js not working in Ionic 3 project(Anime.js 在 Ionic 3 項目中不起作用)
                  Ionic 3 - Update Observable with Asynchronous Data(Ionic 3 - 使用異步數據更新 Observable)
                  Angular 2: file not found on local .json file(Angular 2:在本地 .json 文件中找不到文件)
                  In Ionic 2, how do I create a custom directive that uses Ionic components?(在 Ionic 2 中,如何創建使用 Ionic 組件的自定義指令?)
                  Use ViewChild for dynamic elements - Angular 2 amp; ionic 2(將 ViewChild 用于動態元素 - Angular 2 amp;離子2)
                  <i id='3aVjX'><tr id='3aVjX'><dt id='3aVjX'><q id='3aVjX'><span id='3aVjX'><b id='3aVjX'><form id='3aVjX'><ins id='3aVjX'></ins><ul id='3aVjX'></ul><sub id='3aVjX'></sub></form><legend id='3aVjX'></legend><bdo id='3aVjX'><pre id='3aVjX'><center id='3aVjX'></center></pre></bdo></b><th id='3aVjX'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='3aVjX'><tfoot id='3aVjX'></tfoot><dl id='3aVjX'><fieldset id='3aVjX'></fieldset></dl></div>

                  1. <tfoot id='3aVjX'></tfoot>
                  2. <legend id='3aVjX'><style id='3aVjX'><dir id='3aVjX'><q id='3aVjX'></q></dir></style></legend>

                    <small id='3aVjX'></small><noframes id='3aVjX'>

                        • <bdo id='3aVjX'></bdo><ul id='3aVjX'></ul>
                            <tbody id='3aVjX'></tbody>
                          • 主站蜘蛛池模板: 中文字幕 国产 | 亚洲视频观看 | 成人片免费看 | av日日操 | 中文成人在线 | 天堂久久一区 | 亚洲精品大片 | 欧美a区| 精品视频一区二区在线观看 | 亚洲va欧美va人人爽午夜 | 国产精品毛片一区二区三区 | 成人av播放| 日本在线黄色 | www.精品国产| 懂色av一区二区三区在线播放 | 亚洲欧洲在线视频 | 亚洲网在线 | 亚洲国产精品久久久久婷婷老年 | 欧美亚洲视频 | 美女爽到呻吟久久久久 | 精品日本久久久久久久久久 | 成人黄色电影在线观看 | 日韩欧美三区 | 国产精品久久久久久久久婷婷 | 成人在线观看免费爱爱 | 中文一区二区 | 国产亚洲成av人片在线观看桃 | 一区视频在线 | 在线欧美视频 | 日韩精品一区二区在线观看 | 成人av网站在线观看 | 中文字幕精品视频在线观看 | 国产精品a久久久久 | 欧美一卡二卡在线 | 成人影院网站ww555久久精品 | 久久久精 | 久久免费看 | 久久精品一区 | 在线免费观看黄a | 精品亚洲一区二区三区四区五区 | 精品麻豆剧传媒av国产九九九 |