日期:2014-05-16 浏览次数:20392 次
<!DOCTYPE html> <html> <head> <title></title> <script type="text/javascript"> var a = document.getElementsByTagName('a'); alert(a); </script> </head> <body> <a href="#"></a> <a href="#"></a> <a href="#"></a> <a href="#"></a> </body> </html>
<!DOCTYPE html> <html> <head> <title></title> </head> <body> <a href="#">DEMO</a> <a href="#"></a> <a href="#"></a> <a href="#"></a> <script type="text/javascript"> var a = document.getElementsByTagName('a'); alert(a[0].innerHTML); </script> </body> </html>
------解决方案--------------------
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<a href="#">1</a>
<a href="#">2</a>
<a href="#">3</a>
<a href="#">4</a>
<script type="text/javascript">
var a = document.getElementsByTagName('a');
alert(a[0].innerHTML);
</script>
</body>
</html>
script放dom之后,或window.onload里