//Learning MOOCJS1javascript-Warning (Alert message dialog box)
<script type= "Text/javascript" > var mynum =; Alert ("hello!"); Alert (mynum);</script>
Note: Alert pop-up message dialog box (contains a OK button)
Attention:
1. You cannot do anything else until you click the "OK" button in the dialog box.
2. Message dialogs are commonly used for debugging programs.
3. Alert output can be a string or variable, similar to document.write.
//==================================================================================
Javascript-Confirmation (Confirm message dialog box)
The Confirm Message dialog box is often used to allow the user to make a selection action, such as: "Are you right?" such as A popup dialog box (including a OK button and a Cancel button).
Grammar:
Confirm (str);
Parameter description:
STR: The text return value to display in the message dialog box: Boolean value
return value:
Returns True when the user taps the "OK" button, which returns False when the user taps the "Cancel" button
Note: By returning a value you can tell what button the user clicked.
Look at the following code:
<script type= "Text/javascript" > var mymessage=confirm ("Do you like JavaScript?"); if (mymessage==true) { document.write ("Very good, come on!"); } else { document.write ("JS powerful, to learn Oh!"); } </script>
Results:
Note: The message dialog box is exclusive, that is, the user cannot do anything else until the dialog button is clicked.
//===================================================================================
**javascript-Questions (Prompt message dialog box)
prompt
A pop-up message dialog box is typically used to ask for information that needs to interact with the user. Pop-up message dialog box (contains a OK button, Cancel button and a text input box).
Grammar:
Prompt (str1, str2);
Parameter description:
STR1: The text to display in the message dialog box cannot be modified STR2: The contents of the text box can be modified
return value:
1. Click the OK button and the contents of the text box will return the value 2 as the function. Clicking the Cancel button will return null
Take a look at the following code:
var myname=prompt ("Please enter your name:"), if (myname!=null) { alert ("Hello" +myname);} else { alert ("Hello my friend."); }
Results:
Note: You cannot perform any other action until the user taps the button in the dialog box.
//=============================================================================
javascript-Opening a new window (window.open)
The open () method can look for an existing or new browser window.
Grammar:
window.open ([URL], [window name], [parameter string])
Parameter description:
URL: Optional parameter, in the window to display the Web page's URL or path. If this argument is omitted, or if its value is an empty string, then the window will not display any documents. Window name: Optional parameter, the name of the window being opened. 1. The name consists of letters, numbers, and underscore characters. 2. " _top "," _blank "," _self "have a special meaning name. _blank: Display the target page in a new window _self: Display the target page in the Current window _top: On the frames page, in the upper window, the target page 3. Windows of the same name can only be created one, and if you want to create multiple windows, name cannot be the same. 4.name cannot contain spaces. Parameter string: Optional parameter, set window parameters, each parameter separated by commas.
Parameter table:
For example: Open http://www.imooc.com website, size 300px * 200px, no menu, no toolbar, no status bar, scroll bar window:
<script type= "Text/javascript" > window.open (' http://www.imooc.com ', ' _blank ', ' width=300,height=200,menubar= No,toolbar=no, Status=no,scrollbars=yes ') </script>
Note: The running results consider browser compatibility issues.
javascript-Close window (window.close)
Close () Closes the window
Usage:
Window.close (); Close this window
Or
< Window object >.close (); Closes the specified window
For example, close the newly created window.
<script type= "Text/javascript" > var mywin=window.open (' http://www.imooc.com ');//The newly-hit window object, stored in the variable Mywin mywin.close ();</script>
Note: The code above opens a new window, closes the window, and does not see the window being opened.
JavaScript learns a