.htc文件

来源:百度文库 编辑:神马文学网 时间:2024/04/29 08:35:59
.htc文件是什么?

htc的全称就是Html Components,由微软在IE5.0后开始提供的一种新的指令组合,它可以把某种特定功能的代码封装在一个组件之中,从而实现了代码的重复使用,据说是用来代替activex和applet的.

从 Internet Explorer 5 开始引入了 HTML 组件的概念, HTML 组件也是 Internet Explore 5.5 一个革命性的突破。 Microsoft 的目的是用它取代 ActiveX 控件。HTML 组件是封装的对象,也像 ActiveX 控件一样是“自包含”的,可以在开发完后发布给任何人。HTC 文件并不仅仅是将一个 HTML 文件的扩展名换成 .htc,它含有脚本和 HTC 定制元素的集合。

在 HTML 文件中,HTC 拥有和页面中其他的 DHTML 元素一样的访问方式。这就意味着所有 HTC 元素都可以通过 id 属性在脚本中调用,也就是说 HTC 元素的属性、方法都可以通过脚本来进行灵活的运用。

您可以通过下面几种方式来执行 DHTML 行为:

定义属性和方法。在 HTC 中分别使用 PUBLIC:PROPERTY 和 PUBLIC:METHOD 元素来定义 HTC 的属性和方法。 
定义事件:通过 EVENT 元素定义,使用元素的 fire () 方法在它们所在的页面里 引发这些事件。事件的环境可以通过 createEventObject () 方法设置。 
在它们所在的页面里访问 DHTML 对象模型。HTC 中的 object 元素返回它所附属的元素, 通过这个对象,HTC 能访问他所在的文档及其对象模型 (属性、方法和事件)。 
接受通报。当使用 ATTACH 元素时,浏览器向 HTC 通报标准 DHTML 事件和两个 HTC 专有 事件,oncontentready 和 ondocumentready。

PUBLIC:ATTACH Element

Binds a function to an event, so that the function is called whenever the event fires on the specified object.

Syntax

Copy

Attributes

EVENT
Required. String that specifies the name of a Dynamic HTML (DHTML) event, or any of the events specific to the HTML Component (HTC) that are listed in the HTC Reference.
FOR
Optional. String that specifies one of the following values to identify the source of the event.documentRefers to the document object.elementDefault. Refers to the element to which the behavior is attached.windowRefers to the window object.
ID
Optional. String that uniquely identifies the PUBLIC:ATTACH element within the component. This attribute is analogous to the ID attribute in DHTML.
ONEVENT
Required. String that specifies an inline script or a direct invocation of the event handler function.

Element Information

Parent elementsPUBLIC:COMPONENTChild elementsNoneMinimum availabilityInternet Explorer 5Minimum operating systemsWindows 95, Windows NT 4.0

Remarks

The PUBLIC:ATTACH element is a declarative form of the attachEvent method.

When the specified event fires on the element to which the behavior is attached, the element's event handler is called first, before the behavior's. If multiple behaviors are attached to an element and multiple event handlers are defined for the same event on the same element, the functions are called in random order, immediately after the element's event handler is called.

When providing a value for ONEVENT, avoid assigning the event handler function the name of an existingDHTML event. Using an existing DHTML event name might cause recursion errors.

Event names are case-sensitive for all scripted languages.

Example

This example uses an HTC to implement a table of contents that expands and collapses. The HTC attaches to the element's onclick event, and then expands or collapses the list each time the onclick event is received.

Copy

This feature requires Microsoft Internet Explorer 5 or later. Click the following icon to install the latest version. Then reload this page to view the sample.