<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>[/pre]
下面是 XML 文档 "behave.htc":
[pre]<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>[/pre]
假如您使用 Internet Explorer,可以切身试一下。
<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 does 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>作者: javalearner 时间: 2011-7-29 21:37
谢谢楼主分享。