当前位置: 首页 > 网络学院 > XML相关教程 > 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() |