w3pop.com :: ÍøÂçѧԺ :: XML :: XML DHTMLÐÐΪ
Internet Explorer 5 introduced DHTML behaviors. Behaviors are a way to add DHTML functionality to HTML elements with the ease of CSS.
IE5½éÉÜÁËDHTMLÐÐΪ¡£ÐÐΪÄܹ»¸ü¼ÓÇáËɵÄʹÓòãµþʽÑùʽ±í£¨CSS£©½«DHTML¹¦ÄÜÌí¼Óµ½HTMLÔªËØµÄÒ»ÖÖ·½·¨¡£
IE5 introduced DHTML behaviors. Behaviors are a way to add DHTML functionality to HTML elements with the ease of CSS.
IE5½éÉÜÁËDHTMLÐÐΪ¡£ÐÐΪÄܹ»¸ü¼ÓÇáËɵÄʹÓòãµþʽÑùʽ±í£¨CSS£©½«DHTML¹¦ÄÜÌí¼Óµ½HTMLÔªËØµÄÒ»ÖÖ·½·¨¡£
How do behaviors work? By using XML we can link behaviors to any element in a web page and manipulate that element.
ÐÐΪÊÇÔõÑùÔËÐеģ¿Í¨¹ýʹÓÃXML£¬ÎÒÃÇ¿ÉÒÔ°ÑÐÐΪÓëËùÓÐÒ³ÃæÖеÄÔªËØÏ໥Á¬½ÓÆðÀ´£¬²¢¶ÔÔªËØ½øÐвÙ×÷¡£
DHTML behaviors do not use a <script> tag. Instead, they are using a CSS attribute called "behavior". This "behavior" specifies a URL to an HTC file which contains the actual behavior (The HTC file is written in XML).
DHTMLÐÐΪ²¢²»Ê¹ÓÃ<script>±êÇ©£¬ËüÃÇʹÓõÄÊÇÃûΪ"behavior"µÄCSSÊôÐÔ¡£Õâ¸ö“ÐÐΪ”Ö¸¶¨ÁËÒ»¸öHTCÎļþ£¨HTCÎļþÊÇдÔÚXMLÖе쩵ÄURLÁ´½Ó£¬¸ÃÎļþ°üº¬ÁËÕæÕýʹÓõÄÐÐΪ¡£
behavior: url(some_filename.htc) |
Note: The behavior attribute is only supported by IE 5 and higher, all other browsers will ignore it. This means that Mozilla, Firefox, Netscape and other browsers will only see the regular content and IE 5+ can see the DHTML behaviors.
×¢Ò⣺ÐÐΪÊôÐÔÖ»±»IE5¼°Æä¸ü¸ß°æ±¾µÄä¯ÀÀÆ÷Ö§³Ö£¬ËùÓÐÆäËüµÄä¯ÀÀÆ÷¶¼»áºöÂÔËü¡£ÕâÒâζ×ÅÔÚMozilla¡¢Firefox¡¢NetscapeºÍÆäËüä¯ÀÀÆ÷ÉÏÖ»ÄÜ¿´µ½³£¹æÄÚÈÝ£¬¶øIE5»¹¿ÉÒÔ¿´µ½DHTMLÐÐΪ¡£
Example
Àý×Ó
The following HTML file has a <style> element that defines a behavior for the <h1> element:
ÏÂÃæµÄHTMLÎļþ°üº¬ÁËÒ»¸öÓÃÓÚ¶¨Òå<h1>ÔªËØÐÐΪµÄ<style>ÔªËØ£º
<html> |
The XML document "behave.htc" is shown below:
ÏÂÃæÁоٵÄÊÇXMLÎĵµ "behave.htc"£º
<attach for="element" event="onmouseover" handler="hig_lite" /> function low_lite() |
The behavior file contains a JavaScript and the event handlers for the script.
ÐÐΪÎļþ°üº¬ÁËJavaScript ºÍ´¦Àí½Å±¾³ÌÐòµÄʼþ´¦ÀíÆ÷¡£
Try it yourself (mouse over the text in the example).
³¢ÊÔһϠ(°ÑÊó±êÒÆ¶¯µ½ÎÄ×ÖÉÏ·½).
The following HTML file has a <style> element that defines a behavior for elements with an id of "typing":
ÏÂÊöHTMLÎļþ°üº¬Ò»¸öIDΪ"typing" µÄÔªËØµÄÐÐΪ<style>ÔªËØ£º
<html> |
The XML document "typing.htc" is shown below:
ÏÂÃæÁоٵÄÊÇXMLÎĵµ"typing.htc"£º
<attach for="window" event="onload" handler="beginTyping" /> <script type="text/javascript"> function beginTyping() function type() |