Notes to "Gifted" JavaScript (1) Introduction usage output syntax

Source: Internet
Author: User
Tags button type

JavaScript Basic Note Finishing (1) 2015.05.29

Today's task: Introduction usage Output syntax

I. Introduction to JavaScript

JavaScript is a scripting language

JavaScript is a lightweight programming language that can insert HTML code

What knowledge do you have when you learn JavaScript?

(1) JavaScript: Writing directly to the HTML output stream

document.write ("

(2) JavaScript: Reacting to events

<button type= "button" onclick= "alert (" Welcome! ")" > Point me! </button>

(3) JavaScript: Changing HTML content

X=document.getelementbyid ("demo"); Find element

X.innerhtml= "Hello World JavaScript";//change Content

(4) JavaScript: changing HTML images

function Changeimage () {Element=document.getelementbyid (' myimage ') if (Element.src.match ("Bulbon")) {element.src= " Pic_bulboff.gif ";} Else{element.src= "Pic_bulbon.gif";}}


(5) JavaScript: Changing the style of HTML

X=document.getelementbyid ("demo")//Find element

X.style.color= "#ff0000"; Change Style

(6) JavaScript: Validating input

If IsNaN (x) {alert ("not a Number")};

Second, the use of JS

Two ways to reference Javascript (1) Internal references and (2) external references

(1) Internal references can be placed inside the head or body tag

(2) external reference <script xx.js></script>

Third, the output of JS

(1) Manipulating HTML elements

Use the document.getElementById (ID) method and use innerHTML to get the content of the inserted element document.getElementById ("demo") is a JavaScript that uses the id attribute to find HTML elements Code.

InnerHTML = "Paragraph changed." Is the JavaScript code used to modify the HTML content (InnerHTML) of an element.

(2) write to HTML document

document.write () writes only to the document output

(3) Write to console

The Console.log () method displays JavaScript values in the browser

Four, JS syntax

The number literal can be an integer or a decimal, or a scientific count (e).

String literals can use single or double quotation marks

Array literal defines an array: [40, 100, 1, 5, 25, 10]

Object literal: {firstName: "John", LastName: "Doe", Age:50, Eyecolor: "Blue"}

function literal defines a function: function myFunction (A, b) {return a * b;}

Note:

JavaScript is case sensitive

The syntax for JavaScript functions is function Name (parameter) {}

The JavaScript comment is a multiline comment/* */Single comment//

Tomorrow the JavaScript content is:

JS variable JS data type JS Object JS function

Notes to "Gifted" JavaScript (1) Introduction usage output syntax

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.