Through an instanceCodeTo describe:
<HTML>
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312">
<Title> CSS-expression example </title>
<Style>
Tr
{
Background-color: expression (
(This. sectionrowindex % 2! = 0 )? "White": "# e8e8e8"
);
Mevent: expression (// here, mevent is the custom attribute name.
Onmouseover = function (){
This. style. backgroundcolor = "# 0099cc ";
},
Onmouseout = function (){
This. style. backgroundcolor = "";
}
)
}
</Style>
</Head>
<Body>
<Table name = "tab" id = "tab" width = "100%" border = "1" cellspacing = "0" cellpadding = "0">
<Tr>
<TD> & nbsp; </TD>
<TD> & nbsp; </TD>
<TD> & nbsp; </TD>
<TD> & nbsp; </TD>
</Tr>
<Tr>
<TD> & nbsp; </TD>
<TD> & nbsp; </TD>
<TD> & nbsp; </TD>
<TD> & nbsp; </TD>
</Tr>
<Tr>
<TD> & nbsp; </TD>
<TD> & nbsp; </TD>
<TD> & nbsp; </TD>
<TD> & nbsp; </TD>
</Tr>
<Tr>
<TD> & nbsp; </TD>
<TD> & nbsp; </TD>
<TD> & nbsp; </TD>
<TD> & nbsp; </TD>
</Tr>
</Table>
</Body>
</Html>
We can see two advantages of CSS expression:
1. Batch Processing of HTML Objects greatly simplifies JavaScript code writing.
2. Make CSS and HTML code effectively separated, reduce the Coupling Degree between CSS code and HTML elements, and facilitate code maintenance.
In fact, expression is to embed JS Code into CSS attributes.
however, this method also has a disadvantage, that is, it consumes resources and strictly controls the usage of this method. Otherwise, the page will become very slow.