Study notes. JavaScript Start (ii)

Source: Internet
Author: User

1.<script> tag Properties, methods and event handlers;

Property:

Defer (defer): Specifies whether to delay the execution of the script until the page loads;

src (URL): Specifies the URL of the external script file;

CharSet (CharSet): Specifies the character encoding used by the external script file;

Async: Specifies the asynchronous execution script;

Event: Sets or gets the events that the script is written for;

Htmlfor: Sets or gets the object bound to the event script;

The type, language property has been canceled in the standard.

Method: None

Event: OnError, onload.

2. The function name with parentheses means that the function is being called, and if there is no parentheses, it is assigned to the event handler so that this event occurs when it is run.

3. The comment of the large paragraph adopts/* XXXXX */method, the in-line annotation adopts//xxxx way.

4.<noscript> tags on browsers that do not support JavaScript, a message is displayed that executes the contents of the tag.

<noscript> 

5. Confirm the user's choice.

if (Confirm ("is want to does that?")) {Alert ("you said yes");} else{alert ("You said no");}

The Confirm () method is used to display a dialog box with the specified message and OK and Cancel buttons.
Confirm (message), OK returns True, cancels return false.

(Confirm ("is want to du that?"))? Alert ("You said yes"): alert ("You said no");

6. Prompt the user.

var ans = prompt ("is sure you want to Du", "Default answer ..."), if (ans) {alert ("you said" + ans);} else{alert ("You refused to answer");}

The message passed to the prompt () method is two pieces of information separated by commas: the question to ask the user and the default answer. method returns the user's response or null.

7. Redirect the user with a link.

Window.onload = Initall;function Initall () {document.getElementById ("redirect"). onclick = Initredirect;}    function Initredirect () {window.location = "http://www.baidu.com"; return false;}

The Window.location object is used to obtain the address (URL) of the current page and redirect the browser to a new page.

window.location = "http://www.baidu.com" is equivalent to

Window.location.href = "Http://www.baidu.com"

8. Use JavaScript to improve links.

Window.onload = Initall;function Initall () {document.getElementById ("redirect"). onclick = Initredirect;}    function Initredirect () {//alert ("We are not responsible for the content of pages outside our site."); if (Confirm ("Go on!"))        {window.location.href = this;    return false;    } else{window.location.href = window.location; }}

9. Use multi-level conditions.

Window.onload = initall;function initall () {    document.getelementbyid (" Lincoln "). Onclick = saysomething;    document.getelementbyid (" Kennede "). onclick  = saysomething;    document.getelementbyid ("Nixon") .onclick =  saysomething;} Function saysomething () {    switch (this.id) {         case  "Lincoln":        {             alert ("Four score and seven years ago ... ");            break;         }        case  "Kennede":         {             Alert ("ask not What your country can do for you ... ");             break;        }         case  "Nixon":        {             alert ("i am not a crook!");             break;         }        default:             }}

10. Handling Errors.

<! Doctype html>

Try: Error test code block;

Throw: custom error prompt;

catch (errmsg): code that executes when an error occurs.

This article is from the "Technology No Peak" blog, please be sure to keep this source http://shelia.blog.51cto.com/2930476/1621787

Study notes. JavaScript Start (ii)

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.