JavaScript- output:
document.write()Can be used to write content directly to the HTML output stream. The simple thing is to print the content directly in the Web page.
The first type: The output content is enclosed in "", directly Output "".
<script type= "Text/javascript" > document.write ("I Love javascript! "); Content is output directly from the content in "", "". </script>
The second type: through variables, output content
<script type= "Text/javascript" > var mystr= "Hello world!"; document.write (mystr); Write the variable name directly, and the output variable stores the contents. </script>
The third type: output multiple items, the content is connected with the + number.
<script type= "Text/javascript" > var mystr= "Hello"; document.write (mystr+ "I love JavaScript"); Connect between multiple items with a + sign </script>
The fourth type: output HTML tags, and work, the label using "" enclosed.
<script type= "Text/javascript" > var mystr= "Hello";d ocument.write (mystr+ "<br>");//Output Hello, Outputs a line break document.write ("JavaScript");</script>
javascript-Warning (Alert message dialog box):
When we visit the site, sometimes suddenly pop up a small window, which is written with a text message. If you do not click "OK", you can not do anything to the Web page, this small window is the use of alert implementation.
Grammar:
Alert (string or variable);
Look at the following code:
<script type= "Text/javascript" > var mynum =; Alert ("hello!"); Alert (mynum);</script>
Note: Alert pops up the message dialog box (contains a OK button).
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>
javascript-Questions (Prompt message dialog box)
promptA 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>
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.
The above has a network to provide information!
Getting Started with JavaScript