从动态改变元素(对象)的内嵌样式(in-line style)再看DHTML

王朝网络·html/css/js·作者佚名  2006-01-09
宽屏版  字体: |||超大  

例子:

function onload111() {

for(i=0; i<document.getElementsByTagName("ul")[1].all.tags("a").length; i++){

if(i%2==0){

document.getElementsByTagName("ul")[1].all.tags("a")[i].style.fontWeight="bold";

document.getElementsByTagName("ul")[1].all.tags("a")[i].style.color="red";

}

}

}

document.onreadystatechange = onload111;

这是改变左边BLOG菜单项样式的script:红色加粗

有以下几点

无论脚本放在html文档哪里,全文档对象均可见,关键:onreadystatechange

onreadystatechange :Fires when the state of the object has changed. 这里的对象当然是文档document了。状态state有以下几种:uninitialized loading loaded interactive complete ;

return a collection返回一个集合对象:

If this parameter is a string and there is more than one element with the name or id property equal to the string, the method returns a collection of matching elements.

得到对象引用方法有多种,如上:getElementsByTagName、tags,它们是归属某一个对象(元素)的。同名对象当然返回一个集合了。tags可是集合all的方法,可再返回一个collection。

访问集合的元素:常用有:oItem = object.item(vIndex [, iSubindex]) 和 collElements = object.tags(sTag)

getElementsByTagName、tags返回的集合具有相性质,tagName相同,而all集合是该元素下所有子元素,tagName不一定相同,all.tags( )就像对all进行过滤。下标就无话可说了,集合似乎会排序的,返回唯一引用。

样式标签属性和样式属性

不必说,看看就知道:fontWeight 与 font-weight

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
© 2005- 王朝网络 版权所有