Home > Web Front-end > JS Tutorial > JavaScript Learning Notes JS Event Object_Basic Knowledge

JavaScript Learning Notes JS Event Object_Basic Knowledge

WBOY
Release: 2016-05-16 16:18:32
Original
1410 people have browsed it

Event object: When an event occurs, the browser automatically creates this object and contains the type of event, mouse coordinates, etc.

Attributes of the event object: Format: event. attribute.

Some instructions:

Event represents the status of the event, such as the element that triggered the event object, the position and status of the mouse, the key pressed, etc.;

The event object is only valid during the event.

The events in Firefox are different from those in IE. The events in IE are global variables and can be used at any time. The events in Firefox need to be guided by parameters and are temporary variables at runtime.

In IE/Opera it is window.event, in Firefox it is event;

The event object is window.event.srcElement in IE, event.target in Firefox, and both are available in Opera.

Binding events

There are usually two methods to bind events to an object (control) in JS:

First define a function in head:

Copy code The code is as follows:


The first method of binding events:



The second method of binding events:

Copy code The code is as follows:

        
        

Other examples

Example 1:

Copy code The code is as follows:




eventTest.html




<script><br> Function mOver(object) {<br>           object.color = "red";<br> }<br> Function mOut(object) {<br>           object.color = "blue";<br> }<br> </script>


onclick="window.location.href='http://www.baidu.com'"
onmouseover="mOver(this)" onmouseout="mOut(this)">Welcome




Example 2:

Copy code The code is as follows:




eventTest2.html






   


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template