History对象:有关客户访问过的URL的信息
back() 指加载History列表上的一个URL
back()方法相当于后退按钮
forward() 指加载History列表中的下一个URL
forward()方法相当于前进按钮
go("url" or number) 指指加载History列表中的一个URL或要求浏览器移动指定的页面数
go(1)代表前进1页,等价于forword()方法
go(-1)代表后退1页,等价于back()方法
打开02.html 按钮 所需要的代码
<body>
<input type="button" id="btn1" value="打开02.html" />
<script type="text/javascript">
btn1.onclick=function(){
location.href="index1.html"
}
</script>
</body>
back 打开03.html forword() 按钮所需要的代码
<body>
<input type="button" id="btn1" value="back" />
<input type="button" id="btn2" value="打开03.html" />
<input type="button" id="btn3" value="forward()" />
<input type="button" id="btn4" value="go" />
<script type="text/javascript">
btn1.onclick=function(){
history.back()//返回到上一页
}
btn2.onclick=function(){
location.href="index2.html"//跳转到第三个页面
}
btn3.onclick=function(){
history.forward()//进入下一个页面
}
btn4.onclick=function(){
history.go(1)//进入下一个页面
//history.go(-1)//返回到上一页
}
</script>
</body>
返回02.html go 按钮 的代码
<body>
<input type="button" id="btn1" value="返回02.html" />
<input type="button" id="btn2" value="go" />
<script type="text/javascript">
<script type="text/javascript">
btn1.onclick=function(){
location.href="index1.html"//返回到上一页
}
btn2.onclick=function(){
//history.go(1)//进入下一个页面
history.go(-1)//返回到上一页
}
</script>
</body>
Location对象:有关当前URL的信感息。
属性 说明
host 设智或检索位置或URL的主机名和端口号
hostname 设置或检索位置或URL的主机名部分
href 设置或检索完整的URL字符串
方法 说明
assign(“url”) 加载URL指定的新的HTML文档
reload() 重新加载当前页
replace("url") 通过加载URL指定的文档来替换当前文档
制作如下界面,实现用户名、密码和确认密码的验证,并给与一定的提示消息
<body>
<table border="" cellspacing="0" cellpadding="">
<tr>
<td>账户:</td>
<td>
<input type="text" name="uname" id="uname" value="" onblur="checkUname()" />
</td>
<td>
<label id="msg1"></label>
</td>
</tr>
<tr>
<td>密码:</td>
<td>
<input type="password" name="pwd1" id="pwd1" value="" onblur="checkPwd()" />
</td>
<td>
<label id="msg2"></label>
</td>
</tr>
<tr>
<td>确认密码:</td>
<td>
<input type="password" name="pwd2" id="pwd2" value="" onblur="checkEquals()" />
</td>
<td>
<label id="msg3"></label>
</td>
</tr>
<tr>
<td>家庭住址:</td>
<td>
<select name="province" id="province" onchange="changeOpt()">
<option value="请选择省份">--请选择省份--</option>
<option value="河南省">--河南省--</option>
<option value="四川省">--四川省--</option>
<select>
<select name="cities" id="cities">
<option value="请选择城市">--请选择城市--</option>
<select>
</td>
<td>
</td>
</tr>
<tr>
<td colspan="3" align="center">
<input type="button" id="btn" value="提交" />
</td>
</tr>
</table>
<div id="result">
</div>
<script type="text/javascript">
function checkUname(){
var seg = /^[a-zA-Z]{6,}$/
var usname = document.getElementById("uname").value
if (seg.test(usname)) {
msg1.innerHTML = "用户名正确"
return true
} else {
msg1.innerHTML = "用户名不正确"
return false
}
}
function checkPwd(){
var reg1=/^[0-9a-zA-Z]{6,}$/
var spwd= document.getElementById("pwd1").value
if(reg1.test(spwd)){
msg2.innerHTML="密码正确"
return true
}else {
msg2.innerHTML="密码不正确"
return false
}
}
function checkEquals(){
var spwd =document.getElementById("pwd1").value
var spwd2= document.getElementById("pwd2").value
if(spwd2==spwd){
msg3.innerHTML="正确"
return ture
}
else{
msg3.innerHTML="不正确"
return false
}
}
</script>
</body>
属性,方法,事件
鼠标事件 意义
onmousedown 按下鼠标键
onmousemove 移动鼠标
onmouseout 鼠标离开某一个网页对象
onmouseover 鼠标移动到某一个网页对象上
onmouseup 松开鼠标键
onclick 单击鼠标键
ondblclick 双击鼠标键
键盘事件 意义
onkeydown 按下一个键
onkeyup 松开一个键
onkeypress 按下然后松开一个键
document对象:
每个载入浏览器的html文档都会成为Document对象
事件 说明
onload() 对象装载完成后触发
onkeydown 按下一个键
onkeyup 松开一个键
onkeypress 按下然后松开一个键
onunload() 对象被卸载后触发
onmousedown 按下鼠标键
onmousemove 移动鼠标
onmouseout 鼠标离开当前页面
onmouseover 鼠标移动到当前页面
onmouseup 松开鼠标键
onclick 单击鼠标键
ondblclick 双击鼠标键v
Window对象常用事件:
事件 说明
onload() 对象装载完成后触发
onscroll() 窗口的滚动条被拖动时触发
onresize() 窗口的大小改变时触发
onblur()/onfocus() 窗口失去/获得焦点时触发
onerror() 遇到执行错误时触发
onunload() 对象被卸载后触发