Javascript/15-1-14

Source: Internet
Author: User
Tags button type html form

The 1.break statement is used to jump out of a loop. After the break statement jumps out of the loop, the code after the loop continues to execute, if any. The Continue is used to skip an iteration in the loop.

2 . Label:statements is used to jump directly to the line specified by the identifier and start execution, which can only be used by break and continue.

The 3.try statement tests the code block for errors. The catch statement handles the error. The throw statement creates a custom error.

Try   {  // Run code here   }catch(err)  {  ///  Handling errors here  }

The throw statement allows us to create custom errors.

Syntax: Throw Exception

<script>function MyFunction () {Try  {  varX=document.getelementbyid ("Demo"). Value; if(x=="")Throw "Empty"; if(IsNaN (x))Throw "Not a number"; if(x>Ten)Throw "too high"; if(x<5)Throw "too Low"; }Catch(err) {varY=document.getelementbyid ("mess"); Y.innerhtml="Error:"+ Err +"."; }}</script>5andTen: </p><input id="Demo"Type="text"><button type="Button"onclick="myFunction ()">test input</button><p id="mess"></p>

4.JavaScript can be used to validate these input data in an HTML form before the data is sent to the server.

These typical forms of data that are validated by JavaScript are:

  Has the user filled out the required fields in the form?

is the email address entered by the user legal?

Has the user entered a valid date?

Does the user enter text in the Data field (numeric field)?

Javascript/15-1-14

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.