Getting Started with JavaScript (i)

Source: Internet
Author: User

Part of JavaScript
    1. ECMAScript: It's the core of JavaScript (syntax, variables, data types, statements, functions ...)
    2. DOM: (Document Object model) documents objects
    3. BOM: (Brower object model) browser objects
The syntax of JavaScript
    1. Case sensitive;
    2. Weak type;
    3. Comments are the same as Java;
    4. define variables using Var;
Data types for JavaScript
    1. Raw data type: String, number, Boolean, null, undefined
    2. Application data type: Array, Boolean, Date, Math, number, String, reqexp
The JavaScript operator
    1. = =: It will be converted automatically when making comparisons.
    2. = = =: It does not convert automatically when making comparisons.
    3. Other operators are basically consistent with Java
JavaScript gets element content
    1. Get element: document.getElementById ("id name");

    2. Gets the value inside the element: document.getElementById ("ID name"). Value;

The output of JavaScript
    1. Warning Box: Alert ("string");
    2. Writes to the location specified by the page: InnerHTML ("Write content");
    3. Write content to page: document.write ("Write content");
Form submission events in javascript: onsubmit

Example 1: A simple registration form check

HTML code

<form action= "#" method= "Get" name= "RegForm" onsubmit= "return Checkform ()" >

<table border= "1px" width= "750px" height= "400px" align= "center" cellpadding= "0px" cellspacing= "0px" bgcolor= "white ">

<tr height= "40px" >

<TD colspan= "2" >

<font size= "4" > member Registration </font> &nbsp;&nbsp;&nbsp; USER REGISTER

</td>

</tr>

<tr>

<td>

User name

</td>

<td>

<input type= "text" name= "user" size= "34px" id= "user"/>

</td>

</tr>

<tr>

<td>

Password

</td>

<td>

<input type= "password" name= "password" size= "34px" id= "password"/>

</td>

</tr>

<tr>

<td>

Confirm Password

</td>

<td>

<input type= "Password" name= "Repassword" size= "34px" id= "Repassword" ></input>

</td>

</tr>

<tr>

<td>

Emaile

</td>

<td>

<input type= "text" name= "email" size= "34px" id= "Eamil"/>

</td>

</tr>

<tr>

<td>

Name

</td>

<td>

<input type= "text" name= "username" size= "34px"/>

</td>

</tr>

<tr>

<td>

Gender

</td>

<td>

<input type= "Radio" name= "Sex" value= "male"/> Male

<input type= "Radio" name= "Sex" value= "female"/> Female

</td>

</tr>

<tr>

<td>

Date of birth

</td>

<td>

<input type= "text" name= "Birthday" size= "34px"/>

</td>

</tr>

<tr>

<td>

Verification Code

</td>

<td>

<input type= "text" name= "Yzm"/>

</td>

</tr>

<tr>

<TD colspan= "2" >

<input type= "Submit" value= "register"/>

</td>

</tr>

</table>

</form>

JavaScript code

<script>

Function checkform () {

//alert ("AA");

/** Verify User name */

//1. Get user-entered data

var uvalue = document.getElementById ("user"). Value;

//alert (uvalue);

If (uvalue== ") {

//2. Error message

Alert (" User name cannot be empty! ");

return false;

}

 

/* Check password */

var pValue = document.getElementById ("password"). Value;

If (pvalue== ") {

Alert (" Password cannot be empty! ");

return false;

}

 

/** Check Confirm password */

var rpvalue = document.getElementById ("Repassword"). Value;

if (rpvalue!=pvalue) {

alert ("Two times password input is inconsistent!");

return false;

}

 

/* Check mailbox */

var evalue = document.getElementById ("Eamil"). Value;

If (!/^ ([a-za-z0-9_-]) [email protected] ([a-za-z0-9_-]) + (. [ A-za-z0-9_-]) +/.test (evalue) {

Alert ("The mailbox format is incorrect!");

return false;

}

 

}

</script>

Getting Started with JavaScript (i)

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.