<!DOCTYPE html>
<html>
<style>
span .span1{
display:none;
}
span .span2{
display:none;
}
span .span3{
display:none;
}
</style>
<script>
window.onload=function ()
{
var biaoji=document.getElementsByName('biaoji');
var span=document.getElementsByTagName('span');
var p1=document.getElementsByName('p1');
var p2=document.getElementsByName('p2');
var p3=document.getElementsByName('p3');
var i;
for(i=0;i<biaoji.length;i++)
{
biaoji.index=i;
if(parseInt(biaoji[i].innerHTML)==1)
{
span[i].innerHTML="Hello World";
}
else if(parseInt(biaoji[i].innerHTML)==2)
{
span[i].innerHTML="nimei";
}
else if(parseInt(biaoji[i].innerHTML)==3)
{
p3.style.display = 'block'; //这段代码出错了。不知道是不是需要弄成二维数组的样子才行。。。
}
}
}
</script>
<body>
<div name="biaoji">1</div>
<span><p name="p1" class="span1">我爱你1</p><p name="p2" class="span2">我爱你2</p><p name="p3" class="span3">我爱你3</p></span>
<div name="biaoji">2</div>
<span><p name="p1" class="span1">我爱你7</p><p name="p2" class="span2">我爱你8</p><p name="p3" class="span3">我爱你9</p></span>
<div name="biaoji">3</div>
<span><p name="p1" class="span1">我爱你4</p><p name="p2" class="span2">我爱你5</p><p name="p3" class="span3">我爱你6</p></span>
</body>
</html>
相关分类