久久久久久久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>
                          • 主站蜘蛛池模板: 最新黄色毛片 | sese视频在线观看 | 精品久久久久久久久久久院品网 | 精品日韩一区二区三区av动图 | 国产人成精品一区二区三 | 欧美久久一区 | 天天干狠狠操 | 一级片在线观看 | 国产精品不卡一区二区三区 | 国产1区2区 | a级片在线 | 久久精品国产久精国产 | 亚洲精品日韩在线观看 | 国产精品久久久久久久久久久免费看 | 中文字幕一区二区三区四区不卡 | 日本不卡一二三 | 欧美日韩久久 | 日韩成人免费中文字幕 | 成人黄在线观看 | 国产片淫级awww | 成人精品鲁一区一区二区 | 中文字幕人成人 | 久热久 | 在线观看av网站永久 | 国产一级一级毛片 | 欧美一级片久久 | а_天堂中文最新版地址 | 国产在线一区二区三区 | 国产精品爱久久久久久久 | 久久久久一区二区三区四区 | 亚洲一区中文字幕 | 欧美乱操| 欧美一级片久久 | 国产视频三区 | 依人成人 | 欧美黄色一级毛片 | 国产免费a视频 | 黑人巨大精品 | 97视频人人澡人人爽 | h在线看| 国产精品91网站 |