Basic knowledge of Java Script
1. the basic data type JavaScript provides four basic data types for processing numbers and text numbers, String, Null, and Boolean 1 ). variable Syntax: var variable name = value; variable naming conventions: 1) variable names consist of letters, numbers, underscores, and $2) the first letter of the variable name must be a letter, $, or underline. 3) Reserved Words cannot be used in JavaScript. Note that the variable name is case sensitive. 2 ). type conversion parseInt (String) converts a String to an integer number parseFloat (String) and converts it to a float number 3 ). operator Arithmetic Operator +,-, *,/, %, ++, -- comparison operator = ,! =,>,> =, <, <= Logical operators &, | ,! 4 ). there are two types of single-line comment Syntax: // multi-line comment Syntax:/* Comment content */5 ). flow Control statement Syntax: if Condition Statement switch multi-branch statement for, while, do... The while LOOP statement break and the continue statement break interrupt the running of a loop. The continue statement is used to skip the remaining code blocks and directly go to the next loop for further execution. 6 ). function Definition and call. function declaration Syntax: function name (parameter list) {B. function code block; return expression;} c. function call Syntax: function name (real parameter 1, real parameter 2 ...); Var variable name = function name (real parameter 1, real parameter 2 ...); 7 ). variable scope based on the scope of the variable, variables in JavaScript can be divided into global variables and local variables 8 ). event Processing browser event onload, unonload, onsubmit mouse event onMouseMove, onMouseOver, onMouseOut, onMouseDown, onMouseUp text box event onchange, onselect, onfocus, onblur, 9 ). other onclick 2. browser Object Model Browser object model is a model used to describe the hierarchical relationship between objects. This object model provides an object structure that is independent of content and can interact with browser windows. 1 ). hierarchical Structure of browser objects common methods of window properties and method examples var money = prompt ("Enter withdrawal amount", 100 ); // receiving user input dialog box alert (money); // output 100 var state = conf REM ("your withdrawal amount is" + money); // The confirm and cancel button dialog box alert (state); // return true or false setTimeout ("called function ", "millisecond count") window. open ("adv.html", "", "related attributes"); height: window height; width: window width; top: The pixel value between the window and the top of the screen; left: the pixel value from the window to the left of the screen; toolbar: whether to display the toolbar; yes: display; menubar, scrollbars indicates the menu bar and scroll bar. Resizable: whether to change the window size. yes or 1 indicates whether to allow location: whether to display the address bar; yes indicates whether to allow status: whether to display information in the status bar; yes or 1 indicates yes; the role of the history object: The history object is used to manage the recently accessed URLs in the current window. Common Methods: Note: history. go (-1) is equivalent to history. back () history. go (1) is equivalent to history. forward () Example: <a href = "javascript: history. back () "> back </a> is equivalent to <a href =" javascript: history. go (-1) "> back </a> <a href =" javascript: history. forward () "> forward </a> is equivalent to <a href =" javascript: history. go (1) "> backward </a> locati On Object Function: location object is used to manage the URL Information of the currently opened window. common attributes and Methods: Example: window. location. href = "http://www.baidu.com"; 3. DOM overview DOM-Document Object Model is a set of Web standard DOM of W3C international organization. It is an interface document Object that has nothing to do with browsers, platforms, and languages: the document object represents the common attributes of the entire HTML document loaded in the browser window. Common Methods: document objects can access page elements in four ways. 1) document. all. page element name; 2) document. form name. element name; 3) document. getElementById ("ID name"); 4) document. getElementsByName ("element name ");-------------------------------- -------------------------------------------------------- 1. property example: Turn on the light and turn off the light <script type = "text/javascript"> function setColor _ () {var type = document. getElementById ("setColor "). value; if (type = "turn off the light") {document. getElementById ("setColor "). value = "turn on"; document. bgColor = "black";} else {document. getElementById ("setColor "). value = "turn off the light"; document. bgColor = "white" ;}}</script> 2. <input type = "button" value = "turn off the light" Id = "setColor" onclick = "setColor _ ()" name = "setColor"/> attribute example: the Core code of image advertisement scrolling with the scroll bar is as follows: 1. <script type = "text/javascript"> function move () {document. getElementById ("adv" ).style.top%400%document.doc umentElement. scrollTop + "px";} window. onscroll = move; </script> 2. <div id = "adv" style = "position: absolute; top: 400px; left: 10px; "> </div> example: select all the core code: 1. <scrip T type = "text/javascript"> function isChecked (state) {var v = document. getElementsByName ("lover"); for (var I = 0; I <v. length; I ++) {if (v [I]. type = "checkbox") {v [I]. checked = state ;}}</script> 2. <input type = "radio" name = "ischeck" onclick = "isChecked (true) "/> select <input type =" radio "name =" ischeck "onclick =" isChecked (false) "/> all <br/> <a href =" javascript: isChecked (true) "> select all </a> <a href =" javascript: isChe Cked (false) "> NO </a>