window -- document用于表现HTML页面当前窗体的内容

  • document,中文"文档"
  • document是BOM中最重要对象之一
  • document对象是window对象的属性
  • document对象包含一个节点对象,此对象包含每个单独页面的所有HTML元素,这就是W3C的DOM对象。

document属性

  • cookie -- 用户cookie
  • title -- 当前页面title标签中定义的文字
  • URL -- 当前页面的URL

下面内容的不建议使用

  • alinkColor -- 代表HTML body标签的alink属性
  • bgColor -- 代表HTML body标签的bgcolor属性
  • fgColor -- 代表HTML body标签的text属性
  • linkColor -- 代表HTML body标签的link属性
  • vlinkColor -- 代表HTML body标签的vlink属性
  • lastModified -- 页面最后修改的日期字符串,可以使用Date的构造函数转换为日期,例如:new Date(document.lastModified);
  • referrer -- 浏览器history中后退一个位置的URL

由于document代表HTML文档的内容,因此可以通过它表示文档中加载的一些元素,这些元素全部通过集合访问。

  • anchors -- 文档中所有锚(a name="aname")的集合
  • applets -- 文档中所有applet标签表示的内容的集合
  • embeds -- 文档中所有embed标签表示的内容的集合
  • forms -- 文档中所有form标签表示的内容的集合
  • images -- 文档中所有image标签表示的内容的集合
  • links -- 文档中所有a(链接)标签表示的内容的集合

document函数

  • JavaScript write(str) 函数:在文档中写入字符串
  • JavaScript writeln(str) 函数:在文档中写入字符串,并在字符串的末尾增加一个换行符
  • JavaScript document.open() 函数:打开已经载入的文档
  • JavaScript document.close() 函数:用于关闭document.open方法打开的文档

使用document索引页面内的元素

可以使用数字或名称索引页面中的元素集合,每个元素的属性都变成了集合中相应对象的属性。

示例

<form name="form1"><a href="http://www.dreamdu.com/xhtml/" name="a1">xhtml</a></form>
<form name="form2"><a href="http://www.dreamdu.com/css/" name="a2">css</a></form>
<form name="form3"><a href="http://www.dreamdu.com/javascript/" name="a3">javascript</a></form> <input type="button" value="显示第二个表单的名称" onclick="alert(document.forms[1].name)" />
<input type="button" value="显示第二个表单的名称第二种方法" onclick="alert(document.forms['form2'].name)" />
<input type="button" value="显示第三个链接的名称" onclick="alert(document.links[2].name)" />
<input type="button" value="显示第三个链接的名称第二种方法" onclick="alert(document.links['a3'].name)" />
<input type="button" value="显示第三个链接href属性的值" onclick="alert(document.links[2].href)" />

表示第二个表单的方法:document.forms[1]或document.forms["form2"]

表示第三个链接的方法:document.links[2]或document.links["a3"]

表示第三个链接href属性的方法:document.links[2].href

JavaScript document的更多相关文章

  1. JavaScript document属性和方法

    JavaScript document属性和方法 --------------------------------------------属性: 1. Attributes     存储节点的属性列表 ...

  2. javascript document对象 第21节

    <html> <head> <title>DOM对象</title> <style type="text/css"> t ...

  3. javascript document.referrer 用法

    document对象的referrer属性,返回导航到当前网页的超链接所在网页的URL. 举例: 1. a.html文件内容如下: <a href="b.html">浏 ...

  4. javascript document.write

    在载人页面后,浏览器输出流自动关闭:在此之后,任何一个对当前页面进行操作的document.write()方法将打开—个新的输出流.它将清除当前页面内容(包括源文档的任何变量或值).document. ...

  5. javaScript document对象详解

    Document对象内容集合 document 文挡对象 - JavaScript脚本语言描述———————————————————————注:页面上元素name属性和JavaScript引用的名称必 ...

  6. 关于javascript document.createDocumentFragment() 替代insertCell、insertRow这种每次都使用大量的资源导致浏览器崩溃

    documentFragment 是一個無父對象的document對象他支持以下DOM2方法: appendChild, cloneNode, hasAttributes, hasChildNodes ...

  7. JavaScript document open() 方法:打开一个新文档

    <html> <head> <script type="text/javascript"> function createNewDoc() { ...

  8. Javascript -- document的createDocumentFragment()方法

    在<javascript高级程序设计>一书的6.3.5:创建和操作节点一节中,介绍了几种动态创建html节点的方法,其中有以下几种常见方法: · crateAttribute(name): ...

  9. 详解JavaScript Document对象

    转自:http://segmentfault.com/a/1190000000660947 在浏览器中,与用户进行数据交换都是通过客户端的javascript代码来实现的,而完成这些交互工作大多数是d ...

随机推荐

  1. IOS杂记

    - (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event { //Using code from http://stackoverfl ...

  2. MUI 版本更新

    MUI版本更新,一些js,css  就不写了. 一.app 端 1.APP html 代码 <li class="mui-table-view-cell"> <a ...

  3. form 提交

    1.方式1:字段加验证 @model MvcWeb.Models.UserInfo @{ ViewBag.Title = "Add"; } <h2>Add</h2 ...

  4. office2010官方下载 免费完整版.zip

    office2010官方下载 免费完整版.zip http://pan.baidu.com/share/link?shareid=1103795384&uk=67799523 ________ ...

  5. Python 字符串、元组、字典转换成列表

  6. Examples For PLSQL Cursors - Explicit, Implicit And Ref Cursors

    A cursor acts logically as a pointer into a result set. You can move the cursor through the result s ...

  7. shell应用——主控脚本实现(1)

    shell脚本作用:内网ip,公网ip :cpu负载,内存使用量:ngix和mysql...

  8. Ubuntu下手动安装VMware Tools步骤

    To mount the CD image and extract the contents: Power on the virtual machine. Log in to the virtual ...

  9. C# 线程(四):生产者和消费者

    From : http://kb.cnblogs.com/page/42530/ 前面说过,每个线程都有自己的资源,但是代码区是共享的,即每个线程都可以执行相同的函数.这可能带来的问题就是几个线程同时 ...

  10. Blend操作入门: 别站在门外偷看,快进来吧!(转)

    来源:http://www.cnblogs.com/hielvis/archive/2010/10/21/1857415.html 有的人认为,Blend主要是用来修改一下颜色,调整一下布局之类的,大 ...