js 用firefox的firebug报错误 document.getElementById(cid) is null
firebug显示错误是document.getElementById(cid)isnull请问为什么还包括了个<scriptsrc="js/prototype.js"t...
firebug显示错误是document.getElementById(cid) is null
请问为什么
还包括了个<script src="js/prototype.js" type=text/javascript></script>
<script src="js/fabtabulous.js" type=text/javascript></script>
<script type=text/javascript>
var initialtab = [1, "sc1"]
var previoustab = "";
var intv;
function expandcontent(cid, aobject)
{
stopTimer();
highlighttab(aobject)
if (previoustab != "")
document.getElementById(previoustab).style.display = "none"
document.getElementById(cid).style.display = "block"//错误出现在这一行
previoustab = cid
}
function highlighttab(aobject)
{
stopTimer();
if (typeof tabobjlinks == "undefined")
collectddimagetabs()
for (i = 0; i < tabobjlinks.length; i++)
tabobjlinks[i].className = ""
aobject.className = "current"
}
function collectddimagetabs()
{
var tabobj = document.getElementById("ddimagetabs")
tabobjlinks = tabobj.getElementsByTagName("a")
}
function do_onload()
{
collectddimagetabs()
expandcontent(initialtab[1], tabobjlinks[initialtab[0] - 1])
}
function startTimer()
{
intv = setTimeout("expandcontent(initialtab[1], tabobjlinks[initialtab[0]-1])", 2000);
}
function stopTimer()
{
clearTimeout(intv);
}
Event.observe(window, 'load', do_onload, false);
Event.observe('xcx_tabmenu', 'mouseover', function(event)
{
stopTimer();
}, false);
Event.observe('xcx_tabmenu', 'mouseout', function(event)
{
var reltg = (event.relatedTarget) ? event.relatedTarget : event.toElement;
var tg = (window.event) ? event.srcElement : event.target;
if (tg.nodeName != 'div')
return;
while (reltg != tg && reltg.nodeName != 'body')
{
reltg = reltg.parentNode;
if (reltg.id == "xcx_tabmenu")
return;
}
if (reltg == tg)
return;
stopTimer();
startTimer();
}, false);
</script> 展开
请问为什么
还包括了个<script src="js/prototype.js" type=text/javascript></script>
<script src="js/fabtabulous.js" type=text/javascript></script>
<script type=text/javascript>
var initialtab = [1, "sc1"]
var previoustab = "";
var intv;
function expandcontent(cid, aobject)
{
stopTimer();
highlighttab(aobject)
if (previoustab != "")
document.getElementById(previoustab).style.display = "none"
document.getElementById(cid).style.display = "block"//错误出现在这一行
previoustab = cid
}
function highlighttab(aobject)
{
stopTimer();
if (typeof tabobjlinks == "undefined")
collectddimagetabs()
for (i = 0; i < tabobjlinks.length; i++)
tabobjlinks[i].className = ""
aobject.className = "current"
}
function collectddimagetabs()
{
var tabobj = document.getElementById("ddimagetabs")
tabobjlinks = tabobj.getElementsByTagName("a")
}
function do_onload()
{
collectddimagetabs()
expandcontent(initialtab[1], tabobjlinks[initialtab[0] - 1])
}
function startTimer()
{
intv = setTimeout("expandcontent(initialtab[1], tabobjlinks[initialtab[0]-1])", 2000);
}
function stopTimer()
{
clearTimeout(intv);
}
Event.observe(window, 'load', do_onload, false);
Event.observe('xcx_tabmenu', 'mouseover', function(event)
{
stopTimer();
}, false);
Event.observe('xcx_tabmenu', 'mouseout', function(event)
{
var reltg = (event.relatedTarget) ? event.relatedTarget : event.toElement;
var tg = (window.event) ? event.srcElement : event.target;
if (tg.nodeName != 'div')
return;
while (reltg != tg && reltg.nodeName != 'body')
{
reltg = reltg.parentNode;
if (reltg.id == "xcx_tabmenu")
return;
}
if (reltg == tg)
return;
stopTimer();
startTimer();
}, false);
</script> 展开
2个回答
展开全部
因为在当前document文档不存在一个id为形参cid的控件,所以浏览器无法应用该控件.
首先确定形参cid不为空,你在
function expandcontent(cid, aobject)
{
这个位置用
alert(cid);
测试一下cid是否有值,再判断cid是否在当前文档有对应的控件,id为cid的值.如果以上发现有问题.
下面你再用
document.getElementById(cid)...的时候就会出错.为了避免错误.可加一些判断.如
把你要执行的代码放在
if(document.getElementById(cid)){
//代码实现.
}
首先确定形参cid不为空,你在
function expandcontent(cid, aobject)
{
这个位置用
alert(cid);
测试一下cid是否有值,再判断cid是否在当前文档有对应的控件,id为cid的值.如果以上发现有问题.
下面你再用
document.getElementById(cid)...的时候就会出错.为了避免错误.可加一些判断.如
把你要执行的代码放在
if(document.getElementById(cid)){
//代码实现.
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询