JavaScript Advanced Programming (3rd Edition), chapter 14th

Source: Internet
Author: User
Tags button type

One

<form id= "FormId" name= "FormName" ></form>

1. Get form

var form = Document.queryselector (' #formId '); var form = document.forms["FormName"];

2.button:submit commits and Form.submit () submissions in JavaScript code the subtle differences

<form id= "FormId" name= "FormName" action= "test.php" >    <input type= "text" name= "test" value= "test"/>    <!--<button type= "Submit" >Submit</button>--></form><script>    var form = document.forms["FormName"];     function (e) {        e.preventdefault ();    };     // form.submit ();    // The button:submit button triggers the Submit event, so E.preventdefault () in the onsubmit handler can prevent the form from being submitted. the      form.submit () in JavaScript code does not trigger the submit event, so in this case, the form submission cannot be blocked. </script>

3. Two ways of repeating a form

Disable the Submit button after the first time the form is submitted, or cancel subsequent form submission actions in the onsubmit handler (how do I cancel the doubt?). )。

<form id= "FormId" name= "FormName" action= "test.php" >    <input type= "text" name= "test" value= "test"/>    <button type= "Submit" name= "Submit" >Submit</button></form><script>    var form = document.forms[' FormName '];    Form.addeventlistener (function  (e) {        var target = e.target;         var btn = target.elements[' Submit '];         true ;        E.preventdefault ();    },false); </script>

JavaScript Advanced Programming (3rd Edition), chapter 14th

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.