一、window 对象的属性和方法
<1> Window 对象共有七个属性:
defauleStatus:指定窗口状态栏中的信息。
status:指定当前窗口状态栏中的信息。
frames:是一个数组,其中内容是窗口中所有的框架。
parent:指当前窗口的父窗口。
self:指当前窗口。
top:代表当前所有窗口的最顶层窗口。
window:代表当前窗口
。
<2> Window 对象有五个方法:
alert:显示带有一个“确定”按钮的对话框
confirm:显示带有“确定”与“取消”两个按钮的对话框。
prompt:显示带有输入区的对话框。
open:打开一个新窗口
close:关闭用户打开的窗口。
二、Document 对象的属性和方法
<1> Document 对象有以下属性:
alinkColor:活动链接颜色。
linkColor:链接颜色。
vlinkColor:已访问过的链接颜色。
anchors:页内链接。
bgColor:背景颜色。
fgColor:前景颜色。
cookie:“小甜饼“。
forms:表单元素。
lastModified:文档最后修改的时间。
links:超链接。
location:当前文档的 URL。
referer:在用户跟随链接移动时,包含主文档的 URL 字符串值。
title:文档标题。
<2> Document 对象有四个方法:
write:向文档输出。
open:打开文档。
close:关闭文档。
clear:清除打开文档的内容。
三、History 对象的属性和方法
<1> History 对象只有一个 length 属性,它表示历史对象中的链接的数目。
<2> History 对象有以下方法:
back:在浏览器中显示上一页。
forward:在浏览器中显示上下页。
go(int):在浏览器中载入从当前算起的第 int 个页面。
四、Location 的对象属性和方法
<1>Location 的对象属性
hash 设置或返回从井号 (#) 开始的 URL(锚)。
host 设置或返回主机名和当前 URL 的端口号。
hostname 设置或返回当前 URL 的主机名。
href 设置或返回完整的 URL。
pathname 设置或返回当前 URL 的路径部分。
port 设置或返回当前 URL 的端口号。protocol 设置或返回当前 URL 的协议。
search 设置或返回从问号 (?) 开始的URL(查询部分) 。
<2>Location 的对象方法
assign() 加载新的文档。
reload() 重新加载当前文档。
replace() 用新的文档替换当前文档。
images集合(页面中的图象)
a)通过集合引用
document.images //对应页面上的<img>标签
document.images.length //对应页面上<img>标签的个数
document.images[0] //第1个<img>标签
document.images[i] //第i-1个<img>标签
b)通过nane属性直接引用
<img name="oImage">
document.images.oImage //document.images.name属性
c)引用图片的src属性
document.images.oImage.src //document.images.name属性.src
d)创建一个图象
var oImage
oImage = new Image()
document.images.oImage.src="/1.jpg"
//同时在页面上建立一个<img>标签与之对应就可以显示
<html>
<img name=oImage>
<script language="javascript">
var oImage
oImage = new Image()
document.images.oImage.src="/1.jpg"
</script>
</html>
下拉框列表选中获值
---------------------------------------------------------------------
forms集合(页面中的表单)
a)通过集合引用
document.forms //对应页面上的<form>标签
document.forms.length //对应页面上<form>标签的个数
document.forms[0] //第1个<form>标签
document.forms[i] //第i-1个<form>标签
document.forms[i].length //第i-1个<form>中的控件数
document.forms[i].elements[j] //第i-1个<form>中第j-1个控件
b)通过标签name属性直接引用
<form name="Myform"><inputname="myctrl"></form>
document.Myform.myctrl //document.表单名.控件名
-----------------------------------------------------------------------
<html>
<!--Text控件相关Script-->
<form name="Myform">
<input type="text"name="oText">
<input type="password" name="oPswd">
<form>
<scriptlanguage="javascript">
//获取文本密码框的值
document.write(document.Myform.oText.value)
document.write(document.Myform.oPswd.value)
</script>
</html>
-----------------------------------------------------------------------
<html>
<!--Select控件相关Script-->
<form name="Myform">
<select name="oSelect">
<optionvalue="1">1</option>
<optionvalue="2">2</option>
<optionvalue="3">3</option>
</select>
</form>
<scriptlanguage="javascript">
//遍历select控件的option项
var length
length=document.Myform.oSelect.length
for(i=0;i<length;i++)
document.write(document.Myform.oSelect[i].value)
</script>
<scriptlanguage="javascript">
//遍历option项并且判断某个option是否被选中
for(i=0;i<document.Myform.oSelect.length;i++){
if(document.Myform.oSelect[i].selected!=true)
document.write(document.Myform.oSelect[i].value)
else
document.write("<fontcolor=red>"+document.Myform.oSelect[i].value+"</font>")
}
</script>
<scriptlanguage="javascript">
//根据SelectedIndex打印出选中的option
//(0到document.Myform.oSelect.length-1)
i=document.Myform.oSelect.selectedIndex
document.write(document.Myform.oSelect[i].value)
</script>
<scriptlanguage="javascript">
//动态增加select控件的option项
var oOption = document.createElement("OPTION");
oOption.text="4";
oOption.value="4";
document.Myform.oSelect.add(oOption);
</script>
<html>
-----------------------------------------------------------------------
<Divid="oDiv">Text</Div>
document.all.oDiv //引用图层oDiv
document.all.oDiv.style
document.all.oDiv.style.display="" //图层设置为可视
document.all.oDiv.style.display="none" //图层设置为隐藏
/*document.all表示document中所有对象的集合
只有ie支持此属性,因此也用来判断浏览器的种类*/