XML ×¢ÒâÊÂÏî
±¾½ÚÁгöÁËÄúÔÚʹÓà XML ʱӦ¸Ã¾¡Á¿±ÜÃâʹÓõļ¼Êõ¡£
Internet Explorer - XML Êý¾Ýµº
ËüÊÇʲô£¿XML Êý¾Ýµº£¨XML Data Islands£©ÊÇǶÈë HTML Ò³ÃæÖÐµÄ XML Êý¾Ý¡£
ΪʲôҪ±ÜÃâʹÓÃËü£¿XML Êý¾ÝµºÖ»ÔÚ Internet Explorer ä¯ÀÀÆ÷ÖÐÓÐЧ¡£
ÓÃʲô´úÌæËü£¿ÄúÓ¦µ±ÔÚ HTML ÖÐʹÓà JavaScript ºÍ XML DOM À´½âÎö²¢ÏÔʾ XML¡£
ÈçÐè¸ü¶àÓÐ¹Ø JavaScript ºÍ XML DOM µÄÐÅÏ¢£¬Çë·ÃÎÊ w3school µÄ XML DOM ½Ì³Ì¡£
XML Êý¾ÝµºÊµÀý
±¾ÀýʹÓà XML Îĵµ "cd_catalog.xml"¡£
°Ñ XML Îĵµ°ó¶¨µ½ HTML ÎĵµÖеÄÒ»¸ö <xml> ±êÇ©¡£id ÊôÐÔ¶¨ÒåÊý¾ÝµºµÄ±êʶ·û£¬¶ø src ÊôÐÔÖ¸Ïò XML Îļþ£º
<html>
<body>
<xml id="cdcat" src="cd_catalog.xml"></xml>
<table border="1" datasrc="#cdcat">
<tr>
<td><span datafld="ARTIST"></span></td>
<td><span datafld="TITLE"></span></td>
</tr>
</table>
</body>
</html>
<table> ±êÇ©µÄ datasrc ÊôÐÔ°Ñ HTML ±í¸ñ°ó¶¨µ½ XML Êý¾Ýµº¡£
<span> ±êÇ©ÔÊÐí datafld ÊôÐÔÒýÓÃÒªÏÔʾµÄ XML ÔªËØ¡£ÔÚÕâ¸öÀý×ÓÖУ¬ÒªÒýÓõÄÊÇ "ARTIST" ºÍ "TITLE"¡£µ±¶ÁÈ¡ XML ʱ£¬»áΪÿ¸ö <CD> ÔªËØ´´½¨ÏàÓ¦µÄ±í¸ñÐС£
Èç¹ûÄúÕýÔÚʹÓà Internet Explorer£¬¿ÉÒÔÇ××ÔÊÔÒ»ÊÔ¡£
Internet Explorer - ÐÐΪ
ËüÊÇʲô£¿Internet Explorer 5 ÒýÈëÁËÐÐΪ£¨behaviors£©¡£Behaviors ÊÇͨ¹ýʹÓà CSS ÑùʽÏò XML £¨»ò HTML £©ÔªËØÌí¼ÓÐÐΪµÄÒ»ÖÖ·½·¨¡£
ΪʲôҪ±ÜÃâʹÓÃËü£¿Ö»ÓÐ Internet Explorer Ö§³Ö behavior ÊôÐÔ¡£
ʹÓÃʲô´úÌæËü£¿Ê¹Óà JavaScript ºÍ XML DOM £¨»ò HTML DOM£©À´´úÌæËü¡£
ʵÀý
Àý×Ó 1 - Mouseover Highlight
ÏÂÃæµÄ HTML ÎļþÖÐµÄ <style> ÔªËØÎª <h1> ÔªËØ¶¨ÒåÁËÒ»¸öÐÐΪ£º
<html> <head> <style type="text/css"> h1 { behavior: url(behave.htc) } </style> </head> <body> <h1>Mouse over me!!!</h1> </body> </html>
ÒÔÏÂÊÇ 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>
Õâ¸ö behavior Îļþ°üº¬ÁËÒ»¶Î JavaScript£¬ÒÔ¼°Õë¶ÔÔªËØµÄʼþ¾ä±ú¡£
Ç××ÔÊÔÒ»ÊÔ £¨Çë°ÑÊó±êÒÆµ½Àý×ÓÖеÄÎı¾ÉÏ£©£¨ÇëÔÚ IE ä¯ÀÀÆ÷ÖвâÊÔ±¾Àý£©¡£
Àý×Ó 2 - ´ò×Ö»úÄ£Äâ
ÏÂÃæµÄ HTML ÎļþÖÐµÄ <style> ÔªËØÎª id Ϊ "typing" µÄÔªËØ¶¨ÒåÁËÒ»¸öÐÐΪ£º
<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>
ÒÔÏÂÊÇ 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>