<!-- /* Font Definitions */ @font-face {font-family:Wingdings; panose-1:5 0 0 0 0 0 0 0 0 0; mso-font-charset:2; mso-generic-font-family:auto; mso-font-pitch:variable; mso-font-signature:0 268435456 0 0 -2147483648 0;} @font-face {font-family:宋体; panose-1:2 1 6 0 3 1 1 1 1 1; mso-font-alt:SimSun; mso-font-charset:134; mso-generic-font-family:auto; mso-font-pitch:variable; mso-font-signature:3 135135232 16 0 262145 0;} @font-face {font-family:黑体; panose-1:2 1 6 0 3 1 1 1 1 1; mso-font-alt:SimHei; mso-font-charset:134; mso-generic-font-family:auto; mso-font-pitch:variable; mso-font-signature:1 135135232 16 0 262144 0;} @font-face {font-family:Verdana; panose-1:2 11 6 4 3 5 4 4 2 4; mso-font-charset:0; mso-generic-font-family:swiss; mso-font-pitch:variable; mso-font-signature:536871559 0 0 0 415 0;} @font-face {font-family:"Microsoft Sans Serif"; panose-1:2 11 6 4 2 2 2 2 2 4; mso-font-charset:0; mso-generic-font-family:swiss; mso-font-pitch:variable; mso-font-signature:1627421663 -2147483648 8 0 66047 0;} @font-face {font-family:"/@宋体"; panose-1:2 1 6 0 3 1 1 1 1 1; mso-font-charset:134; mso-generic-font-family:auto; mso-font-pitch:variable; mso-font-signature:3 135135232 16 0 262145 0;} @font-face {font-family:"/@黑体"; panose-1:2 1 6 0 3 1 1 1 1 1; mso-font-charset:134; mso-generic-font-family:auto; mso-font-pitch:variable; mso-font-signature:1 135135232 16 0 262144 0;} /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal {mso-style-parent:""; margin:0cm; margin-bottom:.0001pt; text-align:justify; text-justify:inter-ideograph; mso-pagination:none; font-size:10.5pt; mso-bidi-font-size:12.0pt; font-family:"Times New Roman"; mso-fareast-font-family:宋体; mso-font-kerning:1.0pt;} /* Page Definitions */ @page {mso-page-border-surround-header:no; mso-page-border-surround-footer:no;} @page Section1 {size:612.0pt 792.0pt; margin:72.0pt 90.0pt 72.0pt 90.0pt; mso-header-margin:36.0pt; mso-footer-margin:36.0pt; mso-paper-source:0;} div.Section1 {page:Section1;} -->
1.1. YAHOO工具库提供的方法
l namespace
用于创建一个全局的命名空间,使用YUI时,首先会自动创建widget,util,example三个命名空间,使用时也可以自定义命名空间。类似于在程序中建了了一个static变量。
l lang
javascript扩展的语言工具,用于判别对象的类型。
l lang.extend
用于从一个对象上扩展出另一个对象,模拟了类的继承的方式,但不同的是,在创建子对象时,父对象的构造函数不会自动调用。父对象的引用存放在了子对象的supperclass中,构成了一个链状继承关系。在2.2.2的版本中,YAHOO.lang.extend和YAHOO.extend指向同一函数对象。
l lang.augment
将一个对象的属性(部分或全部)复制到另一个对象,但并非真正意义上的复制,只是一种引用。YAHOO.augment=YAHOO.lang.augment。
l log
用来调试的一个工具,将信息显示到log控件。
l env
环境信息和YUI组件信息
l YUI_config.listener
可以定义自己的回调函数,当有新的YUI组件加载到页面时将会调用YUI_config.listener指向的函数。
2. YUI提供的Dom操作
特点:对于大部分DOM操作提供了批量操作的功能,而对用户只需使用统一的函数接口就能完成单个或批量的操作,主要得益于DOM内部的batch方法。
2.1. Element的查找
YAHOO.util.Dom.get(element)
调用document.getElementById(element),获取指定的页面元素。
YAHOO.util.Dom.getElementsBy(method,tagName,rootNode)
在rootNode的子节点中按照用户提供的method方法在所有标签为tagName的element中查找符合条件的节点。rootNode不指定则在整个Document中查找,method是一个method(elementID)类型的函数对象,该函数对象的返回值为Boolean值。
YAHOO.util.Dom.getElementsByClassName(className, tagName, rootNode)
返回指定根节点下所有标签为tagName,class为className的DOM节点数组。根节点为可选参数,不指定时在整个页面中查找
YAHOO.util.Dom.inDocument (el)
判断元素el是否在当前的DOM中,支持批量操作。
2.2. 样式控制和访问
YAHOO.util.Dom.hasClass(element, className)
判断element标签上是否指明了className的class,支持批量操作
YAHOO.util.Dom.addClass(element, className)
给指定标签增加名为className的class,支持批量操作.
YAHOO.util.Dom.removeClass(element, className)
删除element上的名为className的class,支持批量操作
YAHOO.util.Dom.replaceClass(element, oldClassName, newClassName)
替换element上的oldClassName样式为newClassName,支持批量操作
YAHOO.util.Dom.getStyle(element, property)
获取element的style中的property属性,支持批量操作
YAHOO.util.Dom.setStyle(element,property,pValue)
设置element的style的property属性为pValue,支持批量操作
注:本节中的class指的是CSS中定义的class。