HTML Component (HTC)

xiaoxiao2021-03-06  59

Before Microsoft IE 5.0 version of the browser released, the biggest challenge in web programming is to easily create components to achieve the code reuse and multi-page sharing. This problem has been plaguing DHTML (dynamic HEML) web programming. They can only repeat the code from HTML, CSS, and JavaScript to meet the repetitive or similar functions on multiple pages. After the IE 5.0 browser is released, this situation has been improved, which brings us a new instruction combination method, which can encapsulate the code that implements a specific function in one component, so that the multi-page code is reused, so that web page programming Enter a new world. This new technology is what we have to talk about "Behaviors" in DHTML.

"Behavior" As a simple and easy-to-use component, it encapsulates a specific function or action on the page. When a "behavior" attached to one component in the web page, the original behavior of this component changes. Therefore, web programming can develop universal DHTML instructions and change some properties of the original object, with "behavior" to enhance the functionality of an object, and simplify the HTML code of the page. And "behavior" creation and use is also very simple and convenient, and the knowledge you need is just the CSS style sheet, HTML instruction, and JavaScript scripting language that have been used. As long as you know this, there is a practical programming experience, learning and mastering the use of "behavior" is completely no problem. We will explain how to write and use a "behavior" and experience "Behavior", and experience "Behavior" and experience "Behavior" and experience "behavior". First create a text file called Font_EffTce.htc, which makes up the "Behaviors" component, is the extension of .htc, the content in this file is our description of this "behavior". Its creation and use steps are as follows: (1) First add a few event responses to this "behavior", the statement writing format is as follows: "Event" corresponds to the desired event name, here: OnMouseover, ONMOUSEOUT, ONMOUSEDOWN, ONMOUSEUP four event names, you can of course add additional event names to meet your specific needs. "Onevent" corresponds to a self-event handle, the function name called when the event is triggered. The Glowit () function produces a red glow around the font. Noglow () function is the glow effect of eliminating fonts. The font2yellow () function is to change the color of the font to yellow. The font2bo () function is changed to blue in the font color. The definition of four events is similar. (2) Next, give this "behavior" to add two "method" definitions, the content is as follows. "name" parameter corresponds to a given "method" name. Move_down and Move_Right are the function name corresponding to the "Method" moving downward and right. Note that do not bring "()" brackets behind the method name, ie "Move_Down ()", which is not allowed in the "method" defined syntax. (3) The next job is to write the function content corresponding to the "Event Handle" and "Method" in the DHTML environment we are familiar with, to achieve the intended effect. Specific content refer to the source program below. The "Element" parameter refers to the object attached to this "behavior", because "Behavior" is always attached to the component of the page, and functions in this component. Other statements are DHTML programming content, no more. If there is any unknown, you can refer to Microsoft's MSDN development documentation about IE browser content, with detailed DHTML programming reference content, attributes, and methods for use, etc., and contain a large number of articles and examples.

Regularly visiting Microsoft's MSDN documentation, especially for beginners is a good study habit, you can almost get any answers you want to find, its URL: http: //msdn.microsoft.com/ie/. The complete "behavior" document "font_effect.htc" is as follows: "Behavior" document start // Add four mouse events to "Behavior" < Public: attach event = "onmouseout" onevent = "noglow ()" /> // Define two methods for" behavior "