网站制作

本类阅读TOP10

·IIS 安装配置全攻略
·用VS.NET打开网上下载的.NET web项目出错的解决办法
·HTML 4.0 语言快速参考
·限制TextArea区的文字输入数量
·如何在网页上实现进度条
·Apache的配置步骤及测试
·谈谈Jesse James Garrett提到的Ajax
·html基础学习笔记(2)
·页面垂直居中的两种方法
·用asp遍历目录下文件的例子

分类导航
VC语言Delphi
VB语言ASP
PerlJava
Script数据库
其他语言游戏开发
文件格式网站制作
软件工程.NET开发
从动态改变元素(对象)的内嵌样式(in-line style)再看DHTML

作者:未知 来源:月光软件站 加入时间:2005-2-28 月光软件站

例子:
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:红色加粗

有以下几点

    1. 无论脚本放在html文档哪里,全文档对象均可见,关键:onreadystatechange
      • onreadystatechange :Fires when the state of the object has changed. 这里的对象当然是文档document了。状态state有以下几种:uninitialized loading loaded interactive complete ;
    2. 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进行过滤。下标就无话可说了,集合似乎会排序的,返回唯一引用。
    3. 样式标签属性和样式属性
      不必说,看看就知道:fontWeight 与 font-weight



相关文章

相关软件