JavaScript form validation and window _javascript tips

Source: Internet
Author: User

First, form validation form

1. Create a new form:

Copy Code code as follows:

<form id= "ID is unique, not repeatable" name= "repeatable", method= "Post/get", action= "target or address, responsible for processing the server, transferring text to where" >
Method 1:post no length limit after submission, and the content is not visible after encoding.
Method 2:get commits a length limit, and the encoded content is visible in the address bar
(INPUT Element)
</form>

2, the role of the form: the Web site, the data can be transferred to the database.

3. Action properties: Action and Confirmation button

When the user clicks the Confirm button, the contents of the form are routed to another file. The action properties of the form define the file name of the destination file. This file, defined by the action attribute, usually handles the input data that is received.

Second, javascripewindow--Browser object model

1. Window objects

All Browsers support window objects, which represent browser windows. Global variables are properties of Window objects, and global functions are methods of window objects.

2, Jspopupalert message box

<input name= "" type= "Submit" onclick= "return Tijiao ()" value= "Submit"/><!--Call Method return-->

<!--JS message box-->

1 Confirm the Use of box confirm

Copy Code code as follows:

<!--1. Confirm the use of box confirm-->
<script>
function Tijiao ()
{
var zhi=confirm ("Submit");
if (zhi)
{
return true;
}
Else
{
return false;
}
}
</script>
<!--form when calling a function, add return, otherwise it will not work

2) The use of the prompt box prompt

Copy Code code as follows:

<input name= "" type= "Submit" onclick= "return Tijiao ()" value= "Submit"/><!--Call Method return-->
!--2. The use of the prompt box prompt-->
<script>
function Tijiao ()
{
var zhi=prompt ("Submit");<!--Click the Submit button to appear prompt script cue box-->
if (zhi)
{
return true;
}
Else
{
return false;
}
}
</script>

3 The Use of alert box alert

Copy Code code as follows:

<form action= "" method= "get" >
<label> Please enter your email:</label>
<input name= "" type= "text" id= "Youxiang"/>
<input name= "" type= "Submit" value= "Submit 2" onclick= "Y ()"/>
</form>
function y ()
{
var yx=new RegExp (/^[0-9| a-z|_]{1,17}@[a-z|0-9]{1,5}. (COM|CN|NET|ORG|CC) $/);
var Shuru=document.getelementbyid ("Youxiang"). Value; <!--defines a variable, calls the entire function, and must write the variable within the function-->
if (Yx.test (Shuru)) <!--test Regular expression Method-->
{
Alert ("Zhengque");
}
Else
{
Alert ("Cuowu");
}
}
</script>

3, timing timing method

settimeout (); Executing code at some time in the future--using recursive methods

Cleartimeout (); cancel settimeout ();

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.