Use HTML DOM to assign events--onmouseover and onmouseout, onmousedown and onmouseup

Source: Internet
Author: User

one ,

onmouseover and onmouseout Events

The onmouseover and onmouseout events can be used to trigger a function when a user moves the mouse over an HTML element or moves out of an element.

A small example: the mouse does not move forward above the top

(1) Key code

Style= "Background-color:green;width:120px;height:20px;padding:40px;color: #ffffff;" > Move the mouse over </div><script>function mOver (obj) {obj.innerhtml= "Thank You"} function mout (obj) {obj.innerhtml= "Move mouse over"}</script>
(2) Key code (two ways can be achieved)
<div onmouseover= "innerhtml= ' Thank You '" onmouseout= "innerhtml= ' Move mouse over '"
Style= "Width:120px;height:20px;padding:40px;color: #ffffff;" > Move the mouse over the top </div>

two ,

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.

Cases:

When you do not press the mouse to click the mouse before releasing

(1) Key code
<div onmousedown= "MDown (This)" onmouseup= "mUp (This)" style= "Background-color:green;color: #ffffff;
width:90px;height:20px;padding:40px;font-size:12px; " > Click here </div><script>function mDown (obj) {obj.style.backgroundColor= "#1ec5e5" obj.innerhtml= "Release mouse button"}function mUp (obj) {obj.style.backgroundColor= "Green" "; obj.innerhtml=" Press mouse button "}</script>
(2) Key code (two methods available)


style= "color: #ffffff; width:90px;height:20px;padding:40px;font-size:12px;" > Click here </div>

Use the HTML DOM to assign events--onmouseover and onmouseout, onmousedown and onmouseup

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.