Home  >  Article  >  Web Front-end  >  Examples of six interactive methods commonly used in JavaScript_javascript skills

Examples of six interactive methods commonly used in JavaScript_javascript skills

WBOY
WBOYOriginal
2016-05-16 16:09:541581browse

1.confirm message dialog box

Syntax: confirm("str");

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

Function: It is usually used to remind the user to make certain choices. The return value is a Boolean type. Click to confirm and the return value is true. Click to cancel and the return value is false

For example:

Copy code The code is as follows:


2.prompt message dialog box

Syntax: prompt("str1","str2");

Parameter description: str1 is the text to be displayed in the dialog box and cannot be modified; str2 is the content in the text box and can be modified

Function: Pop up a dialog box to ask for information about interacting with the user

For example:

Copy code The code is as follows:

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

3.window.openopen new window

Syntax: window.open('str1','str2','str3');

Parameter description: str1 is the address of the window to be opened; str2 is the name of the window to be opened; str3 is the parameter to control the window

Function: Open a new window

For example:

Copy code The code is as follows:


4.window.closeClose new window

Syntax: window.close('str'); or .close();

Parameter description: str is the address of the open window

For example:

Copy code The code is as follows:


5.alert warning

Syntax: alert("str");//note the double quotes

Parameter description: str is the content of the dialog box pop-up

For example:

Copy code The code is as follows:


6.document.write output content

Syntax: document.write("str")

Function: Output text str

For example:

Copy code The code is as follows:


The above six points are all the content shared with you in this article. I hope you will like it.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn