最后版本 |
您的文本 |
第3行: |
第3行: |
|
| |
|
|
| |
|
| 您应该在使用 XML 时尽量避免本节列出的技术。 <br>
| |
| Internet Explorer - XML 数据岛<br>
| |
| 它是什么?XML 数据岛是嵌入 HTML 页面中的 XML 数据。<br>
| |
|
| |
|
| 为什么要避免使用它?XML 数据岛只在 IE 浏览器中有效。<br>
| |
|
| |
| 用什么代替它?您应当在 HTML 中使用 JavaScript 和 XML DOM 来解析并显示 XML。<br>
| |
|
| |
| 如需更多有关 JavaScript 和 XML DOM 的信息,请访问 w3school 的 XML DOM 教程。<br>
| |
|
| |
| == XML 数据岛实例 ==
| |
|
| |
| 本例使用 XML 文档 "cd_catalog.xml"。<br>
| |
|
| |
| 把 XML 文档绑定到 HTML 文档中的一个 <xml> 标签。id 属性为数据岛定义标识符,而 src 属性指向 XML 文件:<br>
| |
|
| |
| <html><br>
| |
| <body><br>
| |
| <nowiki> <xml id="cdcat" src="cd_catalog.xml"></xml></nowiki><br>
| |
| <nowiki><table border="1" datasrc="#cdcat"></nowiki><br>
| |
| <nowiki><tr></nowiki><br>
| |
| <nowiki><td><span datafld="ARTIST"></span></td></nowiki><br>
| |
| <nowiki><td><span datafld="TITLE"></span></td></nowiki><br>
| |
| <nowiki></tr></nowiki><br>
| |
| <nowiki></table></nowiki><br>
| |
| </body><br>
| |
| </html><br>
| |
| <table> 标签的 datasrc 属性把 HTML 表格绑定到 XML 数据岛。<br>
| |
|
| |
| <span> 标签允许 datafld 属性引用要显示的 XML 元素。在这个例子中,要引用的是 "ARTIST" 和 "TITLE"。当 XML 被读取时,会为每个 <CD> 元素创建额外的行。<br>
| |
|
| |
| 如果您正在使用 Internet Explorer,可以亲自试一试。<br>
| |
|
| |
| == Internet Explorer - 行为 ==
| |
|
| |
| 它是什么?Internet Explorer 5 引入了行为(behaviors)。Behaviors 是通过使用 CSS 样式向 XML (或 HTML )元素添加行为的一种方法。<br>
| |
|
| |
| 为什么要避免使用它?只有 Internet Explorer 支持 behavior 属性。<br>
| |
|
| |
| 使用什么代替它?使用 JavaScript 和 XML DOM (或 HTML DOM)来代替它。<br>
| |
|
| |
| == 实例 ==
| |
|
| |
| 例子 1 - Mouseover Highlight<br>
| |
| <nowiki>下面的 HTML 文件中的 <style> 元素为 <h1> 元素定义了一个行为:</nowiki><br>
| |
|
| |
| <html><br>
| |
| <nowiki><head></nowiki><br>
| |
| <nowiki><style type="text/css"><nowiki></nowiki><br>
| |
| <nowiki>h1 { behavior: url(behave.htc) }</nowiki><br>
| |
| <nowiki></style></nowiki><br>
| |
| <nowiki></head></nowiki><br>
| |
| <nowiki><body></nowiki><br>
| |
| <nowiki><h1>Mouse over me!!!</h1></nowiki><br>
| |
| <nowiki></body></nowiki><br>
| |
| <nowiki></html>以下是 XML 文档 "behave.htc":</nowiki><br>
| |
| <nowiki><attach for="element" event="onmouseover" handler="hig_lite" /></nowiki><br>
| |
| <nowiki><attach for="element" event="onmouseout" handler="low_lite" /></nowiki><br>
| |
| <nowiki><script type="text/javascript"></nowiki><br>
| |
| <nowiki>function hig_lite()</nowiki><br>
| |
| <nowiki>{</nowiki><br>
| |
| <nowiki>element.style.color='red';</nowiki><br>
| |
| <nowiki>}</nowiki><br>
| |
| <nowiki>function low_lite()</nowiki><br>
| |
| <nowiki>{</nowiki><br>
| |
| <nowiki>element.style.color='blue';</nowiki><br>
| |
| }<br>
| |
| <nowiki></script>这个 behavior 文件包含了一段 JavaScript,以及针对元素的事件句柄。</nowiki><br>
| |
|
| |
|
| |
|
| |
|
| |
| == 例子 2 - 打字机模拟 ==
| |
|
| |
| 下面的 HTML 文件中的 <style> 元素为 id 为 "typing" 的元素定义了一个行为:<br>
| |
|
| |
| <html><br>
| |
| <head><br>
| |
| <style type="text/css"><br>
| |
| #typing<br>
| |
| {<br>
| |
| behavior:url(typing.htc);<br>
| |
| font-family:'courier new';<br>
| |
| }<br>
| |
| </style><br>
| |
| </head><br>
| |
| <body><br>
| |
| <span id="typing" speed="100">IE5 introduced DHTML behaviors.<br>
| |
| Behaviors are a way to add DHTML functionality to HTML elements<br>
| |
| with the ease of CSS.<br /><br />How do behaviors work?<br /><br>
| |
| By using XML we can link behaviors to any element in a web page<br>
| |
| and manipulate that element.</p><br>
| |
| </span><br>
| |
| </body><br>
| |
| </html><br>
| |
| 以下是 XML 文档 "typing.htc":<br>
| |
| <attach for="window" event="onload" handler="beginTyping" /><br>
| |
| <method name="type" /><br>
| |
| < script type="text/javascript"><br>
| |
| var i,text1,text2,textLength,t;
| |
| <br>
| |
| function beginTyping()<br>
| |
| {<br>
| |
| i=0;<br>
| |
| text1=element.innerText;<br>
| |
| textLength=text1.length;<br>
| |
| element.innerText="";<br>
| |
| text2="";<br>
| |
| t=window.setInterval(element.id+".type()",speed);<br>
| |
| }<br>
| |
| function type()<br>
| |
| {<br>
| |
| text2=text2+text1.substring(i,i+1);<br>
| |
| element.innerText=text2;<br>
| |
| i=i+1;<br>
| |
| if (i==textLength)<br>
| |
| {<br>
| |
| clearInterval(t);<br>
| |
| }<br>
| |
| }<br>
| |
| </script><br>
| |
|
| |
|
|
| |
|