JS (1) Less attention to some small things

Source: Internet
Author: User

Confirm Selection

In addition to providing information to users, we also want to get information from users. The Confirm Message dialog box is used here.

Syntax:confirm (str);

Parameter description:

STR: The text to be displayed in the message dialog box, which returns a Boolean value. When the "OK" button is clicked, it returns true, and when the "Cancel" button is clicked, False is returned.

Example:

<! DOCTYPE html>
<title> Confirm Selection </title>
<script>
if (Confirm ("Do you like learning JavaScript?") ") ==true) {
document.write ("Let's Make Progress together");
}else{
document.write ("Work hard, juvenile");
}

</script>

Tips

Sometimes, not only do you want users to answer yes/no. Instead, you want to get a more specific response. We can use prompt in this case.

Syntax:prompt (str1, str2);

Parameter description:

STR1: The text to be displayed in the message dialog box cannot be modified

STR2: The contents of the text box can be modified

Click the OK button, the contents of the text box will be returned as the function return value, click the Cancel button will return null.

<! DOCTYPE html>
<title> Tips </title>
<script>
var myName = prompt ("Enter your Name");
if (myName! = NULL && MyName! = ") {
document.write ("Welcome to" + MyName);
}else{
document.write ("Welcome to my friend.");
}
</script>

Example:

Open a new page

In the HTML page, sometimes we need to jump to a new page. This is the time to use the open ().

Syntax:window.open (URL, window name);

Parameter description:

URL: Optional, open the URL or path of the window. If this argument is omitted, or if its value is an empty string, then the new window will not display any documents.

Window name: Optional, the string is a comma-delimited list of features that declares the name of the window being opened. Can be "_top", "_blank", "_selft", "_parent" and so on.

    • _blank Display the target page in a new window
    • _selft Display the target page in the current window
    • _parent The current entire window position in a frames page displays the destination page
    • _top The target page in the upper window in the frames page
Example:
    1. function Open_win() {
    2. Window. Open("http://www.baidu.com","_blank");
    3. }
    4. Open_win();

Example function: Jump to "http://www.baidu.com" and open in a new window.

JS (1) Less attention to some small things

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.