Tip:
If (confirm ("XXXX "))
{// Return true when "yes" is clicked
Window. Open ("XX ");
} Else
{// Return false when you click "no"
Window. Open ("XXX ");
}
My bug:
A dialog box is displayed before the form is submitted. Check whether the form is submitted. Click "yes" to submit, and click "no" to not submit.
During the test, the page will be submitted whether you click "yes" or "no.
Modified: <SCRIPT type = "text/JavaScript" Language = "JavaScript">
Function check (){
VaR A = Document. Forms [0]. Ss. value;
VaR B = Document. Forms [0]. AA. value;
If (confirm ("Please confirm the data you submitted:" + A + "year" + B + "person ")){
Document. Forms [0]. Submit ();
} Else {
Return false;
}
}
</SCRIPT>
<Form action = "input. jsp" method = "Post" onsubmit = "Return flase">
Year: <select name = "SS">
<Option value = "2010"> 2010 </option>
</SELECT>
Number of students: <input type = "text" name = "AA">
<Input type = "button" value = "OK" onclick = "javascript: Check ()">
</Form>
Summary:The type of the submit button cannot be set to submit.
Form onsubmit verification is not empty
<SCRIPT type = "text/JavaScript" Language = "JavaScript">
<! --
Function isempty (atextfield ){
If (atextfield. value. Length = 0) | (atextfield. value = NULL ))
{
Return true;
} Else
{Return false ;}
}
Function check (){
VaR Mm =/^/d + $ /;
VaR theform = Document. Forms [0];
If (! Theform) {theform = Document. Form [0];}
If (! Mm. Test (theform. allnum. Value ))
{
Alert ('"Total Persons" can only be a number !!!! ');
Theform. allnum. Focus ();
Return false;
}
If (isempty (theform. username ))
{
Alert ('Enter the user name! ');
Theform. username. Focus ();
Return false;
}
Return true;
}
</SCRIPT>
<Form action = "register_conf.jsp" method = "Post" onsubmit = "Return check ()">
<Input type = "button" name = "return" onclick = "javascript: history. Go (-1)" value = "return"/>
<Input type = "Submit" name = "button" value = ""/>
References:
1. Dialog Box:
Prompt dialog box: Alert ('prompt information ');
Confirmation dialog box: Confirm ('Are you sure you want to delete it? ')
Application, for example, in a hyperlink: <a href = "url" target = "_ Self" onclick = "Return confirm ('Are you sure you want to delete it? ') "> When" yes "is clicked, the URL of the connection is redirected. If" no "is clicked, no jump is executed.
Input dialog box: prompt ('title', 'default text'), return the entered information;
Example:
<SCRIPT type = "text/JavaScript" Language = "JavaScript">
X = prompt ("enter a number:", 1 );
Switch (parseint (x ))
{
Case 1:
Case 2:
Case 3:
Document. Write ("winner! ");
Break;
Default:
Alert ("Don't give up! ");
}
</SCRIPT>
3. Several Methods for refreshing pages using JavaScript:
(1) history. Go (0)
(2) location. Reload ()
(3) Location = Location
(4) location. Assign (location)
(5) document.exe ccommand ('refresh ')
(6) window. navigate (location)
(7) location. Replace (location)
(8) document. url = location. href
---------------------------------------------------------------------
4. How to automatically refresh the page:
(1). Automatically refresh the page: Add the following code to the <Meta http-equiv = "refresh" content = "20">
20 indicates refreshing the page every 20 seconds.
(2). automatic page Jump: Add the following code to the <Meta http-equiv = "refresh" content = "20; url = http://www.wyxg.com">
20 means jump to the http://www.wyxg.com page every 20 seconds
(3). Automatically refresh the JS version on the page
<Script language = "JavaScript">
Function myrefresh ()
{
Window. Location. Reload ();
}
SetTimeout ('myrefresh () ', 1000); // refresh once per second
</SCRIPT>
---------------------------------------------------------------------
5. js refresh the framework script statement
// How to refresh the page containing the framework
<Script language = JavaScript>
Parent. Location. Reload ();
</SCRIPT>
// Refresh the parent window in the Child Window
<Script language = JavaScript>
Self. opener. Location. Reload ();
</SCRIPT>
(Or <a href = "javascript: opener. Location. Reload ()"> refresh </a>)
// How to refresh the page of another framework
<Script language = JavaScript>
Parent. Another frameid. Location. Reload ();
</SCRIPT>
If you want to refresh the window when closing the window or refresh the window when opening the window, you can call the following statement in <body>.
<Body onload = "opener. Location. Reload ()"> refresh when opening a window
<Body onUnload = "opener. Location. Reload ()"> refresh when disabled
<Script language = "JavaScript">
Zookeeper opener.doc ument. Location. Reload ()
</SCRIPT>
---------------------------------------------------------------------
6. Locate different resources on the webpage to obtain the URL of the local webpage.
Location. href: Global URL Value
Location. Protocol: the value of the HTTP and FTP protocols in the URL.
Location. hostname: the value of the host name in the URL.
Location. pathname: the value of the path name in the URL.
Location. Port: the value of the port number in the URL.
Location. HOST: host name and port number
---------------------------------------------------------------------
7. Return the last opened Link
Javascript: history. Go (-1 );
---------------------------------------------------------------------
8. Obtain the parameters:
Expected array: mainkinds = request. getparametervalues ("mainkind ");
Obtain a single value: mainkind = request. getparameter ("mainkind ");