0条评论
还没有人评论过~
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<div id="div1">
<span>1</span>
<span>2</span>
</div>
<script type="text/javascript">
var a=document.getElementsByName("span");
var value1=a[0].innerHTML;
var value2=a[1].innerHTML;
console.log(value1);
console.log(value2);
</script>
</body>
</html>
但是我的控制台一直报错
Uncaught TypeError: Cannot read property 'nodeValue' of undefined
搞不懂啊,不知道为什么报错
getElementsByName这个有问题
应该是getElementsByTagName