document对象的属性和方法
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>test10.html</title>
<script type="text/javascript">
//document对象的属性
/*alert(document.referrer);
alert(document.URL);*/
//document对象的方法
function change(){
var objSpan=$("heihei");
objSpan.innerHTML="夏班";
}
function getAllHobbies(){
var hobbies=document.getElementsByName("hobby");
for(var i=0;i<hobbies.length;i++){
$("msg").innerHTML+=hobbies[i].value+" "
}
}
function getAllInputs(){
var inputs=document.getElementsByTagName("input");
for(var i=0;i<inputs.length;i++){
document.getElementById("msg").innerHTML+=inputs[i].value+" "
}
}
//工厂函数,用来简单获取指定ID的元素
function $(id){
return document.getElementById(id);
}
</script>
</head>
<body>
<a href="javascript:location.href=‘test01.html‘">test01</a><br/>
<input type="button" value="刷新" onclick="location.reload();"/><br/>
<input type="button" value="前进" onclick="history.go(1)"/><br/>
<input type="button" value="后退" onclick="history.back();"/><br/>
<span id="heihei">wbs14061</span><input type="button" value="变" onclick="change()" /> <br/>
<h4>请选择爱好:</h4>
<input type="checkbox" name="hobby" value="game" />打游戏
<input type="checkbox" name="hobby" value="movie" />看电影
<input type="checkbox" name="hobby" value="sport" />运动
<input type="checkbox" name="hobby" value="eat" />吃饭
<input type="button" value="获取所有爱好" onclick="getAllHobbies()" /><br/><br/>
<input type="button" value="获取所有input元素" onclick="getAllInputs()" />
<hr/>
<div id="msg"></div>
</body>
</html>
时间: 2024-12-26 19:31:59