代码:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<h1 id="my1">这是h1</h1>
<h1>这是第二个h1</h1>
<h2>这是一个h2</h2>
<input id="my1nput"/>
<script>
var v1=document.getElementById(‘my1‘);
console.log(v1);
var v2=document.getElementsByTagName("h2");
console.log(v2);
for (var i=0;i<v2.length;i++){
console.log(v2[i]);
}
var v3=document.querySelector("#my1");
console.log(v3);
var v4=document.querySelectorAll(‘h1‘);
console.log(v4[0]);
console.log(v4[1]);
var v5=document.querySelector(‘title‘).innerHTML="dom操作";
console.log(v5);
document.querySelector(‘#my1‘).innerHTML=‘这是修改后的H1‘;
document.querySelector(‘input‘).value=‘linzi‘;
</script>
</body>
</html>
后