罗小叉吧 关注:111贴子:19,093
  • 5回复贴,共1

VBS系列课程--26

只看楼主收藏回复

原文地址:
http://blog.sina.com.cn/s/blog_68d342d90100ll6u.html


1楼2010-09-20 10:24回复
    我们这节课来说document对象。
    Document对象代表了当前的HTML文档,它的作用跟window对象同样重要。
    通过document对象我们可以访问页面中的各种元素并可以改变它们的状态,并且我们可以在文档的任意位置使用这个对象。
    一、document对象的属性
    下面我把document对象的各种属性列出来:
    1、alinkcolor:激活的链接颜色
    2、anchors:书签
    3、cookie:就是cookie,不多解释
    4、fgcolor:前景色
    5、forms:文档中的表单
    6、lastModified:文档的最后修改时间
    7、linkcolor:链接的颜色
    8、links:本页面中的链接,数组形式
    9、location:本文档的URL
    10、referrer:返回前一个URL
    11、title:本文档标题
    12、vlinkcolor:访问过的链接颜色
    我们在前边的课程中讲过,在面向对象的编程里,如果我们想访问一个对象的属性,一般都是这样写:
    对象名.属性名
    在这样同样是这样,比如我可以这样使用document对象的属性:
    Document.linkcolor="red"
    通过这样的语句,我就可以在页面中动态的改变页面的链接颜色了。
    二、document对象的方法
    1、open方法
    用来打开一个文档,执行该方法后,当前文档内的所有内容被清除,可以使用write或writeLn方法将新内容写入文档。
    2、write方法
    用于向文档中写入HTML代码
    3、writeLn方法
    同样用于向文档中写入HTML代码,但与write方法不同的是,writeln方法会在写完一句HTML代码后加上一个换行。
    4、close方法
    用来关闭当前文档
    5、clear方法
    用来清除当前文档的内容
    现在我们来写一个脚本文件,来使用上边的知识点:
    ------------------------vbs_24.htm------------------------
    <html>
    <head>
    <title>VBS系列课程--Document对象应用示例</title>
    <script language="vbscript">
    dim a,b
    a=document.linkcolor
    b=document.bgcolor
    sub button1_onclick
    document.linkcolor="red"
    end sub
    sub button2_onclick
    document.linkcolor=a
    end sub
    sub button3_onclick
    document.bgcolor="teal"
    end sub
    sub button4_onclick
    document.bgcolor=b
    end sub
    sub fortext
    form1.text1.value=document.title
    form1.text2.value=document.location
    end sub
    </script>
    </head>
    <body onload="fortext">
    <form name="form1">
    单击这里通过document对象的linkcolor属性来改变当前文档中的链接颜**r>
    <br>
    <input type="button" name="button1" value="单击这里改变">
    &nbsp;&nbsp;&nbsp;&nbsp;
    <input type="button" name="button2" value="单击这里还原">
    <br>
    <br>
    <a href="http://tieba.baidu.com/罗小叉">点击此处访问百度罗小叉吧!</a>
    <br>
    <br>
    单击这里通过document对象的bgcolor属性来改变当前文档中的背景颜**r>
    <br>
    <input type="button" name="button3" value="单击这里改变">
    &nbsp;&nbsp;&nbsp;&nbsp;
    <input type="button" name="button4" value="单击这里还原">
    <br>
    <br>
    本文标题:
    <input type="text" name="text1" size="40">
    本文地址:
    <input type="text" name="text2" size="40">
    <br>
    <br>
    <hr align="left" color="red" size="2" width="80%">
    <br>
    <br>
    本文最新更新日期:
    <script language="vbscript">
    document.write(document.lastmodified)
    </script>
    </form>
    </body>
    </html>
    来看看效果:
    


    2楼2010-09-20 10:24
    回复




      


      3楼2010-09-20 10:25
      回复
        OK,脚本成功运行。
        那么,到这里,我们的VBS系列就完结了,本系列从2010年6月12日开始写,今天是2010年9月20日,呵呵,没想到的是,这个跟HTML系列同样是26节课的VBS系列,前前后后竟然写了3个多月,这中间发生的事情太多了,以至于我的写作进程一直无法顺利进行,不过,时至今日,这个系列最终是没有TJ,还是坚持着写完了,在这里,首先感谢家里老婆对本人工作的大力支持,另外感谢一些朋友对本系列的一贯支持,谢谢。
        VBS完结后,我可能会按照自己QQ空间里的写作计划按部就班的写下去,写作计划地址:
        http://user.qzone.qq.com/673116767/blog/1278675008
        敬请关注,谢谢。
        /**********************************/
        By 杨凡(QQ:673116767)
        Blog:http://blog.sina.com.cn/aboutshisan
        Home:http://tieba.baidu.com/f?kw=%C2%DE%D0%A1%B2%E6
        Date:2010/9/20 10:07
        /**********************************/
        


        4楼2010-09-20 10:26
        回复
          回复:5楼



          6楼2010-09-20 10:45
          回复