Front-end notes (3. JavaScript 1)

Source: Internet
Author: User

JavaScript is a scripting language that belongs to the web!

JavaScript is a lightweight programming language.

JavaScript is a programmatic code that can be inserted into an HTML page.

When JavaScript is inserted into an HTML page, it can be performed by all modern browsers.

(Ps:javascript and Java are two completely different languages, both conceptually and in design.)

Java (by Sun invention) is a more complex programming language.

ECMA-262 is a JavaScript the official name of the standard.

JavaScript by Brendan Eich inventions. It appeared in 1995 in Netscape (the browser has stopped updating) and was in the 1997 Year by the ECMA (a standard association) adopted. )

HTML the script in must be between <script> and </script> tags.

The script can be placed in the <body> and

<type= "Text/javascript"></script  >

Output:

Manipulating HTML elements

If you want to access an HTML element from JavaScript, you can use the document.getElementById (ID) method.

<!DOCTYPE HTML><HTML><Body><H1>My First Web Page</H1><PID= "Demo">My First Paragraph</P><Script>document.getElementById ("Demo"). InnerHTML="My First JavaScript";</Script></Body></HTML>

(JavaScript is performed by a Web browser.) In this case, the browser will access the HTML element of id= "demo" and replace its contents (InnerHTML) with "My first JavaScript". )

Write to document output

The following example writes the <p> element directly to the HTML document output:

<!DOCTYPE HTML><HTML><Body><H1>My First Web Page</H1><Script>document.write ("<p>my First javascript</p>");</Script></Body></HTML>

Warning

Please use document.write () to write only to the document output.

If document.write is executed after the document has finished loading , the entire HTML page will be overwritten:

<!DOCTYPE HTML><HTML><Body><H1>My First Web Page</H1><P>My first Paragraph.</P><Buttononclick= "myFunction ()">Click here</Button><Script>functionmyFunction () {document.write ("Oh, crap! The document disappears. ");}</Script></Body></HTML>

Front-end notes (3. JavaScript 1)

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.