<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>test</title>
<meta name="description" content="">
<meta name="author" content="SYSTEM">
<meta name="viewport" content="width=device-width; initial-scale=1.0">
<style type="text/css">
#div1{
border:1px solid red;
width:100px;
height:200px;
}
</style>
</head>
<body>
<div id="div1">
ABCD
EFG HIJ<br/>KLM N
OPQ<div>RS</div>T
T
<div>
<script type="text/javascript">
alert(document.getElementById("div1").textContent);
</script>
</body>
</html>
火狐下运行结果:
ABCD
EFG HIJKLM N
OPQRST
T
alert(document.getElementById("div1"));
alert(document.getElementById("div1").textContent);
为什么结果中会出现两行alert语句呢?textContent不是返回指定节点的文本内容,以及它的所有后代的文本内容?
你的结尾div没有/闭合~