DOM Event actions in JavaScript
-
- The function is to encapsulate some methods by calling the Execute function.
- Role:
- Avoid repeating the code.
- Simplify programming and make programming modular.
- Syntax: Fuction () {}
- function is a keyword, similar to the "def" of a function defined in Python;
- Enclose parameters in parentheses
- A function statement is placed in curly braces.
- Call to function
- parameters of the function
- Argument: can only be used in functions.
- Number of returned arguments: argument.length
- Returns the number of formal parameters: Fn.length
- Pseudo-Array
- You can modify the element, but you cannot change the length of the array. (Use only the array method)
-
-
-
- Empty array
- Array.splici (0)
- Array.Length = 0
- Array = []
- DOM Event action
- JS is an event-driven core language.
-
- Event three elements:
- Event Source: HTML tag that raises subsequent events
- Event: a drive action
- Event driver: An action on a style or HTML.
-
-
- Gets the event source.
- Get a single tag by ID :getElementById ("ID name") must be quoted and element has no s.
- Get an array of tags by tag name : getElementsByTagName ("tag name"), Elenment has s,
- Get label Group BY class name:getelementsbyclassname ("Class name")Elenment has s,
- The binding event.
- Directly binds an anonymous function.
- Define the function first, and then bind the encapsulated function body.
- Note: The binding is FN, not FN (), and FN () refers to the function's return value.
- In-line methods.
-
- inline style, when you write FN (), you must have parentheses at this point, otherwise parse to a string .
- Write event drivers. Operations on the DOM
-
-
-
- Notes for writing code:
- When writing attribute values in JS, use quotation marks.
- When writing attributes in JS, write a camel's body, such as backgroundcolor.
DOM element manipulation in JavaScript