以下是 JS 分页的代码,在使用浏览器检测功能,发现出现错误信息,请问是什么问题导致的?
Chrome浏览器:
Uncaught TypeError: Cannot read properties of null (reading 'style')
at webyesnonelink (test.htm:181:33)
at HTMLSpanElement.onclick (test.htm:190:82)
Firefox浏览器:
Uncaught TypeError: can't access property "style", document.getElementById() is null
webyesnonelink /test.htm:181
onclick /test.htm:1
代码:
<script type="text/javascript">
function webyesnonelink(num){
for(var id = 1;id<=7;id++)
{
var MrJin="webyesnone_ids"+id;
if(id==num)
document.getElementById(MrJin).style.display="block";
else
document.getElementById(MrJin).style.display="none";
}
if(num==7)
document.getElementById("webyesnonetitle").className="";
}
</script>
<div id="webyesnonetitle" style="margin: 5px 0 15px 0;">
<span class="taggln1 tagglld1" onClick="javascript:webyesnonelink(1)">文字01-分页</span>
<span class="taggln2 tagglld2" onClick="javascript:webyesnonelink(2)">图片02-分页</span>
<span class="taggln3 tagglld3" onClick="javascript:webyesnonelink(3)">音乐03-分页</span>
</div>
<div id="webyesnone_ids1" style="display: block;">
文字文字文字文字!
</div>
<div id="webyesnone_ids2" style="display: none;">
图片图片图片图片!
</div>
<div id="webyesnone_ids3" style="display: none;">
音乐音乐音乐音乐!
</div>
