Common methods of interaction in JavaScript

Source: Internet
Author: User
Tags close close

1.confirm message dialog box

Syntax: Confirm ("str");

Parameter description: STR is the text to be displayed in the dialog box,

Function: Usually to remind the user to make certain choices, its return value is Boolean type, click OK return value is ture, click Cancel return value is False

For example:

<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>
2.prompt message dialog box
Syntax: Prompt ("str1", "str2");
Parameter description: STR1 is the text to be displayed in the dialog box, cannot be modified, STR2 is the contents of the text box, you can modify
Role: Pop up a dialog box asking for information about interacting with the user
For example:
var myname=prompt ("Please enter your name:");
if (myname!=null)  {   alert ("Hello" +myname);} else  {  alert ("Hello my friend.");  
3.window.open Opening a new window
Syntax: window.open (' str1 ', ' str2 ', ' str3 ');
Parameter description: STR1 is the address of the window you want to open; str2 is the name of the window you want to open; STR3 is the parameter of the control window
Role: Open a new window
For example:
<script type= "Text/javascript" >
window.open (' http://www.imooc.com ', ' _blank ', ' width=300,height=200,menubar=no,toolbar=no, status=no,scrollbars= Yes ') </script>

4.window.close Close a new window

Syntax: window.close (' str '), or < new window >.close ();

Parameter description: STR is the address of the open window

For example:

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


5.alert Warning

Syntax: alert ("str");//note is double quotation marks

Parameter description: What str pops up for the dialog box

For example:

<script type= "Text/javascript" > var mynum = 30; Alert ("hello!"); Alert (mynum);</script>


6.document.write Output Content

Syntax: document.write ("str")

Function: Output text str

For example:

</pre><pre name= "Code" class= "JavaScript" ><script type= "Text/javascript" >  document.write ("I Love javascript! "); Content is output directly from the content in "", "". </script>




Common methods of interaction in JavaScript

Related Article

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.