Before the release of Microsoft's IE5.0 browser, the biggest challenge in web programming was that it was not easy to create components to achieve the purpose of code reuse and multi-page sharing. This problem has been plaguing web programmers in DHTML (dynamic HEML). They can only repeat HTML, CSS, and javascript code to satisfy duplicate or similar functions on multiple pages. This situation has been improved since the release of the IE5.0 browser. It brings us a new instruction combination method that can encapsulate code that implements specific functions in one component, thereby realizing multi-page code reuse and bringing web programming into a whole new world. This new technology is the "behaviors" in DHTML that we are going to talk about.
Here is a small example I did:
font_effect.htc
The code is as follows:
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//Add four mouse events to "behavior"
<PUBLIC:ATTACHEVENT="onmouseover"ONEVENT="glowit()"/>
<PUBLIC:ATTACHEVENT="onmouseout"ONEVENT="noglow()"/>
<PUBLIC:ATTACHEVENT="onmousedown"ONEVENT="font2yellow()"/>
<PUBLIC:ATTACHEVENT="onmouseup"ONEVENT="font2blue()"/>
//Define two methods for "behavior", note that NAME value cannot be added with brackets
<PUBLIC:METHODNAME="move_down"/>
<PUBLIC:METHODNAME="move_right"/>
<scriptlanguage="JScript">
//Define a variable that saves the font color
varfont_color;
//Define a method to move text downward
functionmove_down()
{
element.style.posTop+=10;
}
//Define the method of moving text to the right
functionmove_right()
{
element.style.posLeft+=10;
}
//Define the calling function of the mouse onmouseup event
functionfont2blue()
{
if(event.srcElement==element)
{
element.style.color="blue";
}
}
//Define the calling function of the mouse onmousedown event
functionfont2yellow()
{
if(event.srcElement==element)
{
element.style.color="yellow";
}
}
//Define the calling function of the mouse onmouseover event
functionglowit()
{
if(event.srcElement==element)