当前位置: 首页 > news >正文

JavaScript document 对象

 

1.document属性

 

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

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

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

 

2.document函数

 

  • JavaScript write() 函数
  • JavaScript writeln() 函数
  • JavaScript document.open() 函数
  • JavaScript document.close() 函数

   a. document.write -- 在文档中写入字符串

   write函数语法

  document.write(str);

   write函数参数

  • str -- 要写入文档中的字符串

  b.document.writeln -- 在文档中写入字符串,并在字符串的末尾增加一个换行符

  c.document.open -- 打开已经载入的文档  

   示例

 

  var win = window.open("about:blank","dreamdu");

  win.document.open();

  win.document.write("welcome to dreamdu!");

  win.document.close();

 

  首先新建一个空白文档,并打开open,写入内容,最后完成显示关闭文档close。

 

   document.open函数语法

   window.document.open();

 

 d.document.close -- 用于关闭document.open方法打开的文档

   document.close函数语window.document.close();


3.
使用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

转载于:https://www.cnblogs.com/qinxuemei/p/3970453.html

相关文章:

  • [Git].gitignore失效的原因
  • 不知道能不能写小说
  • Appserv配置虚拟主机设置教程
  • 深入理解linux内核: linux内核
  • spring中context:property-placeholder/元素
  • 第二十章、启动流程、模块管理与 Loader
  • 一个体检系统设想
  • 彩生活_百度百科
  • ios 使用自定义字体
  • 从一堆数中随机取出一些值的方法
  • 【MFC】ID命名和数字约定
  • oracle判断视图或者表名存在删除不存在不删除
  • MYSQL 中的变量
  • 记录一些好的Java学习网站
  • c#应用程序如何添加弹出式广告功能
  • [分享]iOS开发-关于在xcode中引用文件夹右边出现问号的解决办法
  • 【108天】Java——《Head First Java》笔记(第1-4章)
  • 【跃迁之路】【735天】程序员高效学习方法论探索系列(实验阶段492-2019.2.25)...
  • Android Studio:GIT提交项目到远程仓库
  • Android 架构优化~MVP 架构改造
  • css布局,左右固定中间自适应实现
  • Golang-长连接-状态推送
  • idea + plantuml 画流程图
  • javascript 总结(常用工具类的封装)
  • js 实现textarea输入字数提示
  • JS基础篇--通过JS生成由字母与数字组合的随机字符串
  • LintCode 31. partitionArray 数组划分
  • node学习系列之简单文件上传
  • python学习笔记 - ThreadLocal
  • QQ浏览器x5内核的兼容性问题
  • Rancher如何对接Ceph-RBD块存储
  • vue学习系列(二)vue-cli
  • 简析gRPC client 连接管理
  • 精彩代码 vue.js
  • 如何正确配置 Ubuntu 14.04 服务器?
  • 三分钟教你同步 Visual Studio Code 设置
  • 三栏布局总结
  • 使用iElevator.js模拟segmentfault的文章标题导航
  • 一天一个设计模式之JS实现——适配器模式
  • 异常机制详解
  • shell使用lftp连接ftp和sftp,并可以指定私钥
  • 关于Android全面屏虚拟导航栏的适配总结
  • ​3ds Max插件CG MAGIC图形板块为您提升线条效率!
  • #Z0458. 树的中心2
  • #Z2294. 打印树的直径
  • #图像处理
  • (1)虚拟机的安装与使用,linux系统安装
  • (3)选择元素——(14)接触DOM元素(Accessing DOM elements)
  • (6)【Python/机器学习/深度学习】Machine-Learning模型与算法应用—使用Adaboost建模及工作环境下的数据分析整理
  • (android 地图实战开发)3 在地图上显示当前位置和自定义银行位置
  • (Redis使用系列) SpringBoot中Redis的RedisConfig 二
  • (二)【Jmeter】专栏实战项目靶场drupal部署
  • (教学思路 C#之类三)方法参数类型(ref、out、parmas)
  • (循环依赖问题)学习spring的第九天
  • (原創) 博客園正式支援VHDL語法著色功能 (SOC) (VHDL)