JavaScript Basics--javascript Getting Started

Source: Internet
Author: User

Getting Started with JavaScript

JavaScript is a lightweight, interpreted web development language that is not very complex and easy to learn. Since all modern browsers are embedded in the JavaScript engine, JavaScript source code can be interpreted directly in the browser, and the user does not have to worry about support issues.

First, insert JavaScript code in the Web page

Using the <script> tag, you can put JavaScript source code directly into the Web document.

"Example 1" Create a new HTML document and save it as test.html, then insert the <script> tag inside the

<HTML>    <Head>        <MetaCharSet= "Utf-8">        <title>JavaScript "Hello"</title>        <Script>document.write ("")        </Script>    </Head><Body></Body></HTML>

The <script> and </script> tags are used together as identifiers for scripting languages to separate other source code from the HTML tags and CSS style code.

When the browser parses the Web page source code, the browser retrieves the <script> tag and automatically calls the JavaScript engine to interpret the character information contained therein.

Document is an object that JavaScript defines in a browser, which represents the contents of an HTML document. Write () is a method of the Document object that represents the output of the specified parameter content in a Web page document.

Effect

Note

1Given the normative structure of the DOM architecture of HTML documents, it is recommended that users write JavaScript scripts in the<Head>And</Head>Between labels, or written in<Body>And</Body>between Labels2 <Script>the label contains 2 properties, type and language. In real-world development, these 2 properties can be omitted because the browser default<Script>the label contains the character information that is the JavaScript script
Second, using JavaScript files

Like CSS files, JavaScript code can be stored in separate files to enhance the repeatable invocation of JavaScript scripts. JavaScript files are hi a text type of file, can be opened and edited in any text editor, javascript file extension js.

Example

A public function that computes the actual length of the string, function strlen (str) {var len;//temporary scalar, stores the actual length of the string Var i;//declares the loop variable len=0;//initializes the temporary variable len to 0for (i=0; i< Str.length; i++) {//loop detect each character in character if (Str.charcodeat (i) > 255) len+=2;//If the current string is a double-byte character, Increment 2 times else len++;//if the current character is a single-byte character, increment 1 times} Return len;//returns the actual length of the string}

Effect

JavaScript Basics--javascript Getting Started

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.