JS batch add onmouseover and onmouseout Behavior

Source: Internet
Author: User

When a page or layer has a large number of identical tags that need to repeatedly use onmouseover and onmouseout behavior, adding each tag will undoubtedly make the page very lengthy, this is the case when I create a table today. Most of the tables with 20 rows and 7 columns have the onmouseover and onmouseout actions. This adds up to a very dense situation and is dizzy. So here comes the good method. The following is the source code and only six of them are taken:

<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<Html xmlns = "http://www.w3.org/1999/xhtml">
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312"/>
<Title> modify DHTML behavior in batches by JS </title>
<Style type = "text/css">
# Vipinfo {width: 847px; margin: 0; padding: 0; text-align: center; font-family:; font-size: 12px; color: # 116b7b; border-top: 1px solid #9dc5d6; border-left: 1px solid #9dc5d6 ;}
# Vipinfo ul {width: 847px; margin: 0; padding: 0 ;}
# Vipinfo ul li {margin: 0; width: 100px; padding-top: 3px; line-height: 24px; float: left; color: # limit b7b; border-bottom: 1px solid #9dc5d6; border-right: 1px solid #9dc5d6 ;}
# Vipinfo ul li. over {background: # 116b7b; color: # fff ;}
# Vipinfo ul li. out {background: # fff; color: # 116b7b ;}
</Style>
</Head>
<Body>
<Script type = "text/javascript">
Window. onload = function change (){
Var vipinfo = document. getElementsByTagName ("li ");
For (var I = 0; I <vipinfo. length; I ++ ){
Vipinfo [I]. onmouseover = inputOver;
Vipinfo [I]. onmouseout = inputOut;
}
}
Function inputOver (event)
{
Var event = event | window. event;
Var source = event. srcElement | event.tar get;
Source. className = "over ";
}
Function inputOut (event)
{
Var event = event | window. event;
Var source = event. srcElement | event.tar get;
Source. className = "out ";
}
</Script>
<Div id = "vipinfo">
<Ul>
<! -- ------------------------------ Table branch line ------------------------------ -->
<Li style = "width: 240px; background: #8B0000; color: # fff;"> <B> member level/permission description </B> </li>
<Li style = "background: # effecb7b; color: # fff;"> visitors </li>
<Li style = "background: # effecb7b; color: # fff;"> temporary member </li>
<Li style = "background: # effecb7b; color: # fff;"> common member </li>
<Li style = "background: # 116b7b; color: # fff;"> bronze member </li>
<Li style = "background: # baib7b; color: # fff;"> Silver member </li>
<Li style = "background: # effecb7b; color: # fff;"> gold member </li>
<! -- ------------------------------ Table branch line ------------------------------ -->
<Li style = "width: 240px; # effecb7b; background: # effecb7b; color: # fff;"> member conditions </li>
<Li> unregistered visitors </li> <li> free registration </li> <li> Free Upgrade </li> <li> payment upgrade </li> <li> only for financial institutions </li>
<! -- ------------------------------ Table branch line ------------------------------ -->
<Li style = "width: 240px; # 116b7b; background: # 116b7b; color: # fff;"> Publish loan supply (co-organizer) Information </li>
<Li> √ </li> <li> √ </li>
<! -- ------------------------------ Table branch line ------------------------------ -->
<Li style = "width: 240px; # 116b7b; background: # 116b7b; color: # fff;"> loan release Demand Information </li>
<Li>-</li> <li> √ </li> <li> √ </li>
<! -- ------------------------------ Table branch line ------------------------------ -->
<Li style = "width: 240px; # effecb7b; background: # effecb7b; color: # fff;"> Publish other information (related services, job search) </li>
<Li>-</li> <li> √ </li> <li> √ </li>
<! -- ------------------------------ Table branch line ------------------------------ -->
<Li style = "width: 240px; # 116b7b; background: # 116b7b; color: # fff;"> Manage all information published by yourself </li>
<Li>-</li> <li> √ </li> <li> √ </li>
</Ul>
</Div>
</Body>
</Html>

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.