BOM--document对象

<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>BOM--document对象</title>
		<script>
			/*
			 document对象:
			    常用对象集合:  forms:代表页面中所有表单的集合   返回值是一个数组
			    常用对象方法:
			    white():文档中打印信息
			    whiteln():文档打印信息,自带换行
			    getElementById():根据元素的id值获取页面元素
			    getElementsByName():根据元素的name获取一组页面元素,返回值是数组
			    getElementsByTagName():根据元素的名称获取一组页面元素,返回值是数组
			    getElementsByClassName():根据元素的class值获取一组页面元素,返回值是数组 
			    history:记录访问过的对象
			      go()
			      back()==go(-1)
			      forward()==go(1)
			    location对象
			    
			 */
			
			function sub(){
				document.forms[0].action="demo04.html";//想更改路径时可以使用此语句
				document.forms[0].submit();//只有一个form,就获取第一个     
			}
			
			document.writeln("aaaaa");
			document.writeln("bbbbb");
			
			
			
			function load(){
				var div1 = document.getElementById("div1");
			    console.log(div1);
			    var chks = document.getElementsByName("chk");
			    console.log(chks);
			    var lis = document.getElementsByTagName("li");
			    console.log(lis);
			    var liss = document.getElementsByClassName("d");
			    console.log(liss); 
			}
			
			//看地址栏的相关属性
			console.log(location.host);
			console.log(location.hostname);
			console.log(location.href);
			console.log(location.pathname);
			console.log(location.port);
			//实现页面的重新加载
			location.reload();
			
			
		</script>
	</head>
	<body onload="load()"><!--页面加载完成后再执行上边load事件-->
		<form action="demo05.html" method="get" ><!--action:指定表单提交路径,method:表单提交方式-->
			<button type="button" onclick="sub()">提交</button>
		</form>
		<div id="div1">
			<a href="">XXXX</a>
		</div>
		<div>
			<input type="checkbox" name="chk" value="1" />1
			<input type="checkbox" name="chk" value="2" />2
			<input type="checkbox" name="chk" value="3" />3
		</div>
		<div>
			<ul>
				<li class="d">aaaaaaa</li>
				<li class="d">bbbbbbb</li>
				<li class="d">ccccccc</li>
			</ul>
		</div>
	</body>
</html>

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/gcyqweasd/article/details/113789483