这个Javascript代码可能是错误:
var page1selector=document.getElementById('page1_selector');
var page1anchor=page1selector.document.getElementsByTagName('a');
var page2selector=document.getElementById('page2_selector');
var page2anchor=page2selector.document.getElementsByTagName('a');
var page2name="Who are we?";
var page1name="Home";
page2anchor[0].innerHTML=page2name;
page1anchor[0].innerHTML=page1name;
document.getElementById("menu_div").style.marginLeft = screen.width/2;
,HTML是
<?php
?>
<html>
<head>
<meta charset="UTF-8">
<script src="mainjs.js"></script>
<link rel="stylesheet" href="maincss.css">
<title> Home </title>
</head>
<body>
<div id="menu_div" class="menu_div_class">
<ul id="menu">
<li id="page1_selector"><a id="ul_a" style="color:red;" href="index.php"></a></li>
<li id="page2_selector"><a id="ul_a" id="page2a" href="page2.php"></a></li>
</ul>
</div>
<div id="page_content">
<h1 id="page_content_h1">Welcome to Test D2E5</h1>
<p>This is a test project involving new types of information</p>
</div>
</body>
<footer>
</footer>
</html>
问题是它一直告诉我page1selector和page2selector为null。在我添加page1selector之前,它工作正常。