First, what is Java script?
Abbreviation: JS. is part of the front-end knowledge, which is used to send commands to the browser to tell the browser what to do. JS is similar to a general programming language. But there may be differences in syntax. The basic knowledge of learning is divided into: variables, loops, functions, library functions and so on.
Second, the variable
JavaScript is sensitive to capitalization. and weaken the data type
tip: A good programming habit is to declare the required variables at the beginning of the code.
One statement, multiple variables
var name= "G", age=1, job= "CTO";
Declarations can also span multiple lines: var name= "G"; age=1; job= "CTO"; var carname; The value of the variable carname will be undefined var carname= "Volvo"; var carname;//after execution of the following two statements, the value of the variable carname remains "Volvo" JavaScript has a dynamic type. This means that the same variable can be used as a different type var x;//x is undefined var x = 6;//x is the number var x = "Add";//x is a numeric type for string JavaScript. Numbers can be taken with decimal points or withoutformat of the array:var cars=new Array (); Cars[0]= "A"; Cars[1]= "B"; Cars[2]= "C"; or Var cars=new Array ("A", "B", "C"), or Var cars= "" A "," B "," C ""Tip: Array subscripts are zero-based, so the first item is [0], the second is [1], and so on. The format of the object (in JavaScript, the object is the data that owns the property and Method):Objects are separated by curly braces. Inside the parentheses, the properties of the object are defined in the form of name and value pairs (name:value). The attributes are separated by commas: Var person={name: "Wangnima", Sex: "Unknown", id:11111111}; Create object: var x = new Object (); x.name = "Wangnima"; X.sex = "Unknown"; X.id = "666"; Two ways to address the object: (1) name = Person.name; (2) name = person["name"] Undefined and nullundefined This value indicates that the variable does not contain a value you can empty the variable by setting the value of the variable to null. All things in JavaScript are objects.
declaring variable types:New variable, you can use the keyword "new" to declare its type: var x = new String;var x = new Number;var x = new Boolean;var x = new Arrary;var x = new Object ();Conditional operators:(1)
greeting= (visitor== "PRES")? " Dear president ":" Dear ";//If the value in the variable visitor is "PRES", assign a value of "Dear president" to the variable greeting, otherwise assign a value of "Dear". (2) if condition {} else {} Loop: (1) for loop var i =2,len=s.length;For (; i<len;<i++) {} var i =2;len = s.length;For (;i<len;) {i++;} var x = {name: "Wangnima", Sex: "Buming", id= "666"}For (i in x) {}(2) While loop while (I < 5) {i++}function: JavaScript test and capture (used in functions):The Try statement allows us to define a block of code that performs error testing at execution time. The catch statement allows us to define a block of code that executes when a try block of code has an error.a Try catch is a paired occurrence. Syntax: try{//run code here} catch (err) {Handling errors here} changing HTML Properties: document.getElementById ("image"). src= "landscape.jpg"; change HTML Style: document.getElementById ("P2"). style.color= " Blue "; Respond to Events: document.getElementById (" mybtn "). Onclick=function () {displaydate ()};onload and OnUnload events: OnLoad and The OnUnload event is triggered when the user enters or leaves the page. Eg: <body onload= "checkcookies ()" >onmouseover and onmouseout events: onmouseover and onmouseout events can be used to move the user's mouse to HTML The function is triggered when the element is above or removed. OnMouseDown, onmouseup, and onclick events: onmousedown, onmouseup, and onclick form all parts of the mouse click event. First, when the mouse button is clicked, the OnMouseDown event is triggered, and when the mouse button is released, the OnMouseUp event is triggered, and the onclick event is triggered when the mouse click is completed. The EXEC (): EXEC () method retrieves the specified value in a string. The return value is the value that was found. If no match is found, NULL is returned. Window method: window.open ()-Opens a new window Window.close ()-Closes the current window Window.moveto ()-Moves the current window Window.resizeto ()-Adjusts the current window's Dimensions window screen : Screen.availwidth-Available screen width screen.availheight-Available Screen Height window location:window.location object can be written without using window This prefix location.hostname returns the web host's domain name Location.pathname returns the path and text of the current pageThe name Location.port returns the web host's port (80 or 443) Location.protocol returns the Web protocol used (http:///https://) Window History:history.back ()- With the same history.forward () in the browser click Back button-the same as in the browser click the button forward Window.navigator object contains information about the visitor's browser. Warning Box: alert ("Text") Confirmation Box: Confirm ("text") Prompt box: prompt ("text", "Default value") Summary: JS syntax is so much, as long as the basic grammar mastered, after the use of most will be search corresponding library function. Of course JS also has many frameworks (JavaScript frameworks, etc.
), providing a more convenient way to program. Post-Learning ~ ~ ~
Basic Learning for Java script