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.
"Behavior" is a simple and easy-to-use component that encapsulates specific functions or actions on the page. When an "behavior" is attached to a component in the WEB page, the original behavior of the component will change. Therefore, web programmers can develop common DHTML instructions and change some properties of the original object, use "behavior" to enhance the function of an object, and simplify the HTML code of the page. Moreover, the creation and use of "behavior" is also very simple and convenient, and the knowledge required is only the CSS style sheets, HTML directives and javascript script languages that were used to. As long as you have some understanding of this and have had practical programming experience, there is no problem in learning and mastering the use of "behavior". We will use a "behavior" component that changes the effect of fonts as an example to illustrate how to write and use a "behavior" and experience the advantages and conveniences that "behavior" brings to page editing.
First, create a new text file named font_efftce.htc. The files that make up the "behavior" component are all with .htc as the extension. The content in this file is our description of this "behavior". Its creation and use steps are as follows:
(1) First add several event responses to this "behavior". The statement writing format is as follows:
<PUBLIC:ATTACHEVENT="onmouseover"ONEVENT="glowit()"/>
<PUBLIC:ATTACHEVENT="onmouseout"ONEVENT="noglow()"/>
<PUBLIC:ATTACHEVENT="onmousedown"ONEVENT="font2yellow()"/>
<PUBLIC:ATTACHEVENT="onmouseup"ONEVENT="font2blue()"/>
"EVENT" corresponds to the required event names, here are: onmouseover, onmouseout, onmousedown, and onmouseup. Of course, you can add other event names to meet your specific needs. "ONEVENT" corresponds to an event handle, that is, the name of the function called when the event is triggered. The glowit() function causes a red glow to be generated around the font. The noglow() function eliminates the glow effect of fonts. The Font2yellow() function changes the font color to yellow. The Font2blue() function changes the font color to blue. The definitions of the four events are all similar.
(2) Next, add two "methods" definitions to this "behavior", as follows.
<PUBLIC:METHODNAME="move_down"/>
<PUBLIC:METHODNAME="move_right"/>