JS event-triggered object action

Source: Internet
Author: User

Since learning W3C standards Code I seem to have developed a kind of quirks that can be reused in a unified manner, so that I won't write more things, so that the front-end Page code looks much refreshed, and the efficiency will also rise in a straight line. Copy code The Code is as follows: <SCRIPT type = "text/JavaScript">
<! --
// Define the range of mouse-triggered events
Function findoutdiv (thisevent ){
// Use loops to find objects that match the CSS style name
While (thisevent. classname! = "Piccell "){
// If the tag name of this object is HTML, stop the object and make the event object non-existent. Use the tag name for subsequent judgment.
If (thisevent. tagname = "html "){
Thisevent = false;
Break;
} Else {
// Otherwise, continue the next object, that is, its parent object.
Thisevent = thisevent. parentnode
}
}
// Returns the event object. If the event object does not exist, false is returned.
Return thisevent;
}
// Trigger behavior by moving the property of the object with the mouse as the time
Document. onmouseover = function (e ){
// This e is the method used by Firefox to capture the event trigger object.
If (! E) E = Window. event;
// Define the object that the event gives to the mouse to trigger the object, that is, the object that complies with the standard and can be controlled
// Target is for FF and srcelement is for IE
VaR event = e.tar get? E.tar get: E. srcelement
// Define controllable objects and call the mouse to trigger the objects returned by the event range
VaR thisevent = findoutdiv (Event)
// Continue if the object exists
If (thisevent ){
// Define the CSS style for the object
Thisevent. style. Border = "2px solid #7a99d2 ";
Thisevent. style. Background = "# d2e4fc ";
}
}
// Same as above, triggered by moving the mouse out of an object as a time
Document. onmouseout = function (e ){
If (! E) E = Window. event;
VaR event = e.tar get? E.tar get: E. srcelement
VaR thisevent = findoutdiv (Event)
If (thisevent ){
Thisevent. style. Border = "2px solid # CCC ";
Thisevent. style. Background = "# fff ";
}
}
// -->
</SCRIPT>

the advantage of writing is obvious. You do not need to write trigger actions in each object, which greatly saves code and makes JavaScript readable.
after some time, I will release the personalized page, so that you can see the benefits of using events to trigger object actions.
Google and Microsoft Live have well written their personalized pages, so everyone can learn their code, this will be of great help to your future Ajax applications.

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.