<!DOCTYPE html>
<html>
<head>
<title>Get Elements</title>
<meta charset="utf-8" />
</head>
<body>
<a id='baidu'><b>百度一下,你就知道</b></a>
<div class="poem">记住爱</div>
<div class="poem">记住时光</div>
<div class="poem">记住我们共同走过的岁月</div>
<span name="song">Best Friend</span>
<span name="song">All of me</span>
<span name="song">Let her go</span>
</span>
</body>
<script>
//将id='baidu'的内容获取到,并保存到一个变量中
var baidu = document.getElementById('baidu');
//打印baidu
//alert(baidu);这样打印,会发现什么都没有
alert(baidu.innerHTML);//输出结果<b>百度一下,你就知道</b>
alert(baidu.innerText);//百度一下,你就知道
//打印poem
var poem = document.getElementsByClassName('poem');
alert(poem[0].innerHTML);//记住爱
alert(poem[1].innerHTML);//记住时光
alert(poem[2].innerHTML);//记住我们共同走过的岁月
//获取song的内容
//查找的内容显示在浏览器中
var aSong = document.getElementsByName('song');
alert(aSong[0].innerText);//Best Firend
alert(aSong[1].innerText);//All of me
alert(aSong[2].innerText);//Let her go
</script>
</html>