JS Learning Notes

Source: Internet
Author: User

Confirmation (Confirm message dialog box)

Grammar:

Confirm (str);

Parameter description:

STR: The text  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

<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>

Note: The message dialog box is exclusive, that is, the user cannot do anything else until the dialog button is clicked.

Ask a question (Prompt message dialog 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

var myname=prompt ("Please enter your name:"); if (myname!=null)  {   alert ("Hello" +myname);} Else   {  alert ("Hello my friend.");  }

Open a new window (window.open)

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 "," _selft "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.

For example: Open http://www.imooc.com website, size 300px * 200px, no menu, no toolbar, no status bar, scroll bar window:

1 <script type= "Text/javascript" >
window.open (' http://www.imooc.com ', ' _blank ', ' width=300,height=200,menubar=no,toolbar=no, status=no,scrollbars= Yes ')2 </script>

Close Window (window.close)

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// New Window object, stored in variable mywin    Mywin.close (); </script>

Document Object Model DOM

JS Learning Notes

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.