Home  >  Article  >  Web Front-end  >  JavaScript学习笔记之内置对象_基础知识

JavaScript学习笔记之内置对象_基础知识

WBOY
WBOYOriginal
2016-05-16 16:18:301411browse

JS Window

  窗口对象:http://www.w3school.com.cn/js/js_window.asp

  所有浏览器都支持window对象。它表示浏览器窗口。

  所有 JavaScript 全局对象、函数以及变量均自动成为window对象的成员。

  窗口对象的属性和方法格式:

  [window.]属性

  [window.]方法(参数)

  甚至 HTML DOM 的 document 也是 window 对象的属性之一:

window.document.getElementById("header");
  与此相同:

document.getElementById("header");
 
JS Screen

  屏幕对象:http://www.w3school.com.cn/js/js_window_screen.asp

  屏幕对象主要描述屏幕的显示及颜色属性。

  屏幕对象的属性:

  格式:screen.属性

  screen.availWidth - 可用的屏幕宽度

  screen.availHeight - 可用的屏幕高度

  以像素计,减去界面特性,比如窗口任务栏。

JS Location

  位置对象:http://www.w3school.com.cn/js/js_window_location.asp

  位置对象用来代表特定窗口的URL信息。

  window.location 对象在编写时可不使用 window 这个前缀。

  一些例子:

  location.hostname 返回 web 主机的域名

  location.pathname 返回当前页面的路径和文件名

  location.port 返回 web 主机的端口(80 或 443)

  location.protocol 返回所使用的web协议(http:// 或 https://)

  location.href 属性返回当前页面的 URL。

  location.assign() 方法加载新的文档。

JS History

  历史对象:http://www.w3school.com.cn/js/js_window_history.asp

  历史对象用以存储客户端最近访问的网址清单。

  为了保护用户隐私,对 JavaScript 访问该对象的方法做出了限制。

  一些方法:

  history.back() - 与在浏览器点击后退按钮相同

  history.forward() - 与在浏览器中点击按钮向前相同

文件对象

  文件对象: 代表当前HTML对象,是由

标签组构成的,对每个HTML文件会自动建立一个文件对象。

  格式:

  document.属性

  document.方法(参数)

链接对象

  网页中的链接均会被自动看作链接对象,并依顺序,分别表示为document.links[0],document.links[1]...

  定义链接对象的格式:

  字串.link(属性)

表单对象
  文件对象的子对象,Javascript的runtime engine自动为每一个表单建立一个表单对象。

  格式:

  document.forms[索引].属性

  document.forms[索引].方法(参数)

  document.表单名称.属性

  document.表单名称.方法(参数)

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn