<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>网页名称</title>
<style>
</style>
</head>
<body>
<h1 class="www">标题1</h1>
<h1>标题2</h1>
<h1 id="bt3">标题3</h1>
<form name="ne"></form>
<p class="nav">nav1</p>
<p class="nav">nav2</p>
<script>
//标签名获取元素
var h1 = document.getElementsByTagName("h1")[1];
console.log(h1);
h1.innerHTML = "通过获取标签名更改内容";
//类名获取元素
var www = document.getElementsByClassName("www")[0];
www.innerHTML = "通过获取类名更改内容";
//name获取元素
var ne = document.getElementsByName("ne");
console.log(ne);
//id名获取元素
var bt3 = document.getElementById("bt3");
bt3.innerHTML = "通过获取Id名更改内容";
//css选择器获取元素,单个
var nav = document.querySelector(".nav");
console.log(nav);
//css选择器获取元素,全部
var nav1 = document.querySelectorAll(".nav");
console.log(nav1);
//css选择器获取元素,第几个
var nav2 = document.querySelectorAll(".nav")[1];
console.log(nav2);
</script>
</body>
</html>