htc的全稱(chēng)就是Html Components,由微軟在IE5.0后開(kāi)始提供的一種新的指令組合,它可以把某種特定功能的代碼封裝在一個(gè)組件之中,從而實(shí)現了代碼的重復使用,據說(shuō)是用來(lái)代替activex和applet的.
從 Internet Explorer 5 開(kāi)始引入了 HTML 組件的概念, HTML 組件也是 Internet Explore 5.5 一個(gè)革命性的突破。 Microsoft 的目的是用它取代 ActiveX 控件。HTML 組件是封裝的對象,也像 ActiveX 控件一樣是“自包含”的,可以在開(kāi)發(fā)完后發(fā)布給任何人。HTC 文件并不僅僅是將一個(gè) HTML 文件的擴展名換成 .htc,它含有腳本和 HTC 定制元素的集合。
在 HTML 文件中,HTC 擁有和頁(yè)面中其他的 DHTML 元素一樣的訪(fǎng)問(wèn)方式。這就意味著(zhù)所有 HTC 元素都可以通過(guò) id 屬性在腳本中調用,也就是說(shuō) HTC 元素的屬性、方法都可以通過(guò)腳本來(lái)進(jìn)行靈活的運用。
您可以通過(guò)下面幾種方式來(lái)執行 DHTML 行為:
定義屬性和方法。在 HTC 中分別使用 PUBLIC:PROPERTY 和 PUBLIC:METHOD 元素來(lái)定義 HTC 的屬性和方法。
定義事件:通過(guò) EVENT 元素定義,使用元素的 fire () 方法在它們所在的頁(yè)面里 引發(fā)這些事件。事件的環(huán)境可以通過(guò) createEventObject () 方法設置。
在它們所在的頁(yè)面里訪(fǎng)問(wèn) DHTML 對象模型。HTC 中的 object 元素返回它所附屬的元素, 通過(guò)這個(gè)對象,HTC 能訪(fǎng)問(wèn)他所在的文檔及其對象模型 (屬性、方法和事件)。
接受通報。當使用 ATTACH 元素時(shí),瀏覽器向 HTC 通報標準 DHTML 事件和兩個(gè) HTC 專(zhuān)有 事件,oncontentready 和 ondocumentready。
Binds a function to an event, so that the function is called whenever the event fires on the specified object. Syntax Attributes Element Information 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. 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.documentRefers to the document object. element Default. Refers to the element to which the behavior is attached. windowRefers to the window object. Parent elements PUBLIC:COMPONENT Child elements None Minimum availability Internet Explorer 5 Minimum operating systems Windows 95, Windows NT 4.0 <PUBLIC:PROPERTY NAME="child" /><PUBLIC:ATTACH EVENT="onclick" ONEVENT="ExpandCollapse()" /><SCRIPT LANGUAGE="JScript">function ExpandCollapse(){ var i; var sDisplay; // Determine current state of the list (expanded or collapsed) // based on the current display property of the child. bCollapsed = (element.document.all(child).style.display == "none"); if (bCollapsed) { style.listStyleImage = "url('/workshop/graphics/blueminus.gif')"; element.document.all(child).style.display = ""; } else { style.listStyleImage = "url('/workshop/graphics/blueplus.gif')"; element.document.all(child).style.display = "none"; }}</SCRIPT>
聯(lián)系客服