We are able to react to HTML events through DOM events. As we write the GUI in other programming languages, what events does HTML contain? Here are a few common examples, for example, the page has been completed, the image is loaded, the mouse moves over the element. The input text is changed. Form submission. The user clicks the button and so on, still is quite many.
Let's use the example to illustrate the following HTML code:
It was supposed to be Sinsing. If we click on it, it will become "Xiao Qian", where the onclick is actually a click event, the two quotes inside the JavaScript code, then since it is JavaScript code, we'd better write them out in the script tag outside, For example, the following code:
In fact the function and the above code is the same, but also click "Sinsing". Then it becomes "Xiao Qian". Above, we have written directly into the HTML code, some people may ask: can you directly solve the problem in JavaScript? The answer is yes, such as the following code:In fact, it's very well understood. This is also a binding of the DOM, just the binding of the event that it finished directly in JavaScript. Every time we click on the "Sinsing" event, it runs the function, which is the function of changing the text display information.
What are some of the more important events besides the onclick event? The first is the OnLoad event, which is triggered when the user enters the page, and onunload is triggered when the user leaves the page. These two events are good for dealing with cookies, and we will be exposed to cookies later on. The other is the onchange event. It is often used in conjunction with validation of input fields, such as the ability to use the event in an input box or password box to detect user-entered information, while onmouseover is triggered when the mouse moves over the HTML element. The onmouseout is triggered when the mouse moves out of the HTML element. Relative to the onclick this click Process, onmousedown, onmouseup is more careful, the former means we use the mouse to click on the button when the trigger, the latter is when we release the trigger. 2014 Sinsing interpreting JavaScript's DOM events and their bindings