A brief talk on JavaScript event processing _ Basic knowledge

Source: Internet
Author: User

Event handling

One, event Source: Any HTML element (node), body, Div, button

II. Events: your operation

Mouse:
Click
Dblick Double click
OnContextMenu Text Menu

Copy Code code as follows:

<body oncontextmenu= "return false" >//a program that disables the right key

MouseOver, put it on.
Mouseout leave
MouseDown Press the
MouseUp Lift Up
MouseMove Mouse Movement

Keyboard:
KeyPress keyboard Events
KeyUp Lift Up
KeyDown Press the

Document:
Load load
OnLoad is the event that is triggered after a page load completes
Unload off
Before Breforeunload closes

Form:
Focus Event
Blur lose focus
Submit Commit Event
Change events

Other:
Scroll scrolling
Selectstart Select Event

Iii. Event handlers

First type:
Format: <tag on event = "event handler"/>
Instance:

Copy Code code as follows:

<script>
Function Show () {
var One=document.getelementbyid ("one");
alert (One.innertext);
}
Show ();
</script>
<body>
<div id= "One" >
Wwwwwwwwwwwwwwwww
</div>
<input type= "button" onclick= "Show ()" Value= "Show" >

The second type:
Directly inside the JavaScript object. On handler

Copy Code code as follows:

<div id= "Two" >
Hello, cloud-dwelling community http://www.jb51.net
</div>
<script>
var One=document.getelementbyid ("two");
One.onclick=function () {
This.style.backgroundcolor= "Red";
}
</script>

The third type:
Basically no one to use

Copy Code code as follows:

<script for= "event source ID" event= "event" > event handler </script>
<div id= "th" >
Hello, cloud-dwelling community http://www.jb51.net
</div>
<script for= "th" event= "onclick" >
var One=document.getelementbyid ("th");
One.style.backgroundcolor= "Red";
</script>

Small partners understand the JavaScript event processing, if you have any questions, leave me a message.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.