简单问题,高手帮忙看一下~~~~~代码
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN ">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME= "Generator " CONTENT= "EditPlus ">
<META NAME= "Author " CONTENT= " ">
<META NAME= "Keywords " CONTENT= " ">
<META NAME= "Description " CONTENT= " ">
</HEAD>
<script language= 'javascript '>
var a=document.getElementById( "star1 ").nextSibling;
</script>
<BODY>
<div id= "outerGalaxy ">
<ul id= "starList ">
<li id= "star1 ">
Rigel
</li>
<li id= "star2 ">
Altair
</li>
<li id= "star3 ">
Betelgeuse
</li>
</ul>
</div>
</BODY>
</HTML>
为什么
var a=document.getElementById( "star1 ").nextSibling;
这句话报错误?错在那里/?谢谢
------解决方案-------------------- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN ">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME= "Generator " CONTENT= "EditPlus ">
<META NAME= "Author " CONTENT= " ">
<META NAME= "Keywords " CONTENT= " ">
<META NAME= "Description " CONTENT= " ">
</HEAD>
<BODY>
<div id= "outerGalaxy ">
<ul id= "starList ">
<li id= "star1 ">
Rigel
</li>
<li id= "star2 ">
Altair
</li>
<li id= "star3 ">
Betelgeuse
</li>
</ul>
</div>
</BODY>
</HTML>
<script language= 'javascript '>
var a=document.getElementById( "star1 ").nextSibling;
</script>
---------------------------
放到下面就不会错了,
在运行var a=document.getElementById( "star1 ").nextSibling; 时候,star1对象还没有生成,
怎么会有
document.getElementById( "star1 ")????
------解决方案--------------------错在执行顺序
把js脚本放在star1对象之后就可以了