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