ÍøÂçѧԺ w3popÉçÇø ÍøÂç×ÊÔ´ ITÐÂÎÅ

w3pop.com :: ÍøÂçѧԺ :: XML :: XML DHTMLÐÐΪ

»áÔ±µÇ½

ÕʺÅ

ÃÜÂë

»Ø´ð

¼ÇסÃÜÂë

Íü¼ÇÃÜÂë? ×¢²á

XML
XML DHTMLÐÐΪ
XML Ïà¹Ø¼¼Êõ
XML ±à¼­Æ÷
XML ÕªÒª
XML ʵÀý
XML×Ö·û±àÂë
xml ÎĵµÊ÷
IEºÍ»ðºü¶ÁÈ¡XML·..

XML DHTMLÐÐΪ


×÷Õß:w3pop.com ·­Òë/ÕûÀí:w3pop.com ·¢²¼:2007-04-29 ÐÞ¸Ä:2007-08-16 ä¯ÀÀ:3104 :: ::

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ÔªËØµÄÒ»ÖÖ·½·¨¡£


Behaviors - What are They?
ʲôÊÇÐÐΪ — ËüÃǵ½µ×ÊÇʲô£¿

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Á´½Ó£¬¸ÃÎļþ°üº¬ÁËÕæÕýʹÓõÄÐÐΪ¡£

Syntax
Óï·¨

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>

<head>
<style type="text/css">
h1 { behavior: url(behave.htc) }
</style>
</head>

<body>
<h1>Mouse over me!!!</h1>

</body>
</html>

The XML document "behave.htc" is shown below:
ÏÂÃæÁоٵÄÊÇXMLÎĵµ "behave.htc"£º

<attach for="element" event="onmouseover" handler="hig_lite" />

<attach for="element" event="onmouseout" handler="low_lite" />

<script type="text/javascript">
function hig_lite()
{
element.style.color='red'
}
function low_lite()
{
element.style.color='blue'
}
</script>

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>
<head>
<style type="text/css">
#typing
{
behavior:url(typing.htc);
font-family:'courier new';
}
</style>
</head>

<body>

<span id="typing" speed="100">IE5 introduced DHTML behaviors.
Behaviors are a way to add DHTML functionality to HTML elements
with the ease of CSS.<br /><br />How do behaviors work?<br />
By using XML we can link behaviors to any element in a web page
and manipulate that element.</p>
</span>
</body>

</html>

The XML document "typing.htc" is shown below:
ÏÂÃæÁоٵÄÊÇXMLÎĵµ"typing.htc"£º

<attach for="window" event="onload" handler="beginTyping" />

<method name="type" />
<script type="text/javascript">
var i,text1,text2,textLength,t
function beginTyping()
{
i=0
text1=element.innerText
textLength=text1.length
element.innerText=""
text2=""
t=window.setInterval(element.id+".type()",speed)
}
function type()
{
text2=text2+text1.substring(i,i+1)
element.innerText=text2
i=i+1
if (i==textLength){clearInterval(t)}
}
</script>

×Ô¼º³¢ÊÔÒ»ÏÂ

ÆÀÂÛ (3) 1 All