很多人都有类似的问题,但是似乎都不太一样。代码如下:
function setOverColor(iid, fid){
document.getElementById(iid).style.color = '#000000';
switch(iid)
{
case 'Info':
document.getElementById(iid).src = 'Icon_Info_a.gif';
break;
case 'Quick_Start':
document.getElementById(iid).src = 'Icon_Quick_Start_a.gif';
break;
case 'Advanced':
document.getElementById(iid).src = 'Icon_Advanced_a.gif';
break;
//case 'Wireless':
// document.getElementById(iid).src = 'Icon_Wireless_a.gif';
// break;
//case 'Voice':
// document.getElementById(iid).src = 'Icon_Voice_a.gif';
// break;
case 'Diagnostic':
document.getElementById(iid).src = 'Icon_Diagnostic_a.gif';
break;
case 'Management':
document.getElementById(iid).src = 'Icon_Management_a.gif';
break;
default:
break;
}
document.getElementById(fid).style.color = '#000000';
}
function setOutColor(iid, fid){
if(iid != curCate)
{
var name = 'Icon_'.concat(iid);
document.getElementById(iid).style.color = '#FFFFFF';
document.getElementById(fid).style.color = '#FFFFFF';
document.getElementById(iid).src = name.concat(".gif");
}
}
每次到'Managment'的时候都会有问题,说缺少对象,其它几个一样的方法做的,都没问题,实在找不到原因了,望大侠指点。
function setOverColor(iid, fid){
document.getElementById(iid).style.color = '#000000';
switch(iid)
{
case 'Info':
document.getElementById(iid).src = 'Icon_Info_a.gif';
break;
case 'Quick_Start':
document.getElementById(iid).src = 'Icon_Quick_Start_a.gif';
break;
case 'Advanced':
document.getElementById(iid).src = 'Icon_Advanced_a.gif';
break;
//case 'Wireless':
// document.getElementById(iid).src = 'Icon_Wireless_a.gif';
// break;
//case 'Voice':
// document.getElementById(iid).src = 'Icon_Voice_a.gif';
// break;
case 'Diagnostic':
document.getElementById(iid).src = 'Icon_Diagnostic_a.gif';
break;
case 'Management':
document.getElementById(iid).src = 'Icon_Management_a.gif';
break;
default:
break;
}
document.getElementById(fid).style.color = '#000000';
}
function setOutColor(iid, fid){
if(iid != curCate)
{
var name = 'Icon_'.concat(iid);
document.getElementById(iid).style.color = '#FFFFFF';
document.getElementById(fid).style.color = '#FFFFFF';
document.getElementById(iid).src = name.concat(".gif");
}
}
每次到'Managment'的时候都会有问题,说缺少对象,其它几个一样的方法做的,都没问题,实在找不到原因了,望大侠指点。
<table border="0" cellpadding="0" cellspacing="0" width="1800" height="75" bordercolor="#000000" bgcolor='#FFFFFF' valign="top">
<tbody>
<tr>
<script language="javascript">
<!-- hide
//if (window.navigator.appName=='Netscape')
// document.writeln("<td width='17%' valign='bottom'><input id='Logo' type='image' src='logo.gif' onclick='push(this)'/> </td> ");
//else if(window.navigator.appName=='Microsoft Internet Explorer')
{
document.writeln("<td width='210' align='center' valign='center' rowspan='2' bgcolor='#FFFFFF'><input id='Logo' type='image' src='logo.gif' onclick='push(this)'/> </td> ");
}
//chenyb added for ENKOM 20100610
/*Device Info*/
document.writeln("<td width='100' align='center' bgcolor='#AD2721'>")
document.writeln(" <input id='Info' type='image' src='Icon_Info.gif' width=30 heigth=30 onmouseover=\"setOverColor('Info', 'info_font')\" onmouseout=\"setOutColor('Info', 'info_font')\" onclick='push(this)'/>")
document.writeln("</td> ")
/*Quick Start*/
document.writeln("<td width='100' align='center'bgcolor='#AD2721'> ");
document.writeln(" <input id='Quick_Start' type='image' src='Icon_Quick_Start.gif' width=30 heigth=30 onmouseover=\"setOverColor('Quick_Start', 'qstart_font')\" onmouseout=\"setOutColor('Quick_Start', 'qstart_font')\" onclick='push(this)'>");
document.writeln("</td>");
/*Advanced*/
document.writeln("<td width='100' align='center' bgcolor='#AD2721'>");
document.writeln(" <input id='Advanced' type='image' src='Icon_Advanced.gif' width=30 heigth=30 onmouseover=\"setOverColor('Advanced', 'advanced_font')\" onmouseout=\"setOutColor('Advanced', 'advanced_font')\" onclick='push(this)'/>");
document.writeln("</td>");
/*Wireless*/
//document.writeln("<td width='100' align='center'bgcolor='#AD2721'>");
//document.writeln(" <input id='Wireless' type='image' src='Icon_Wireless.gif' width=30 heigth=30 onmouseover=\"setOverColor('Wireless', 'wireless_font')\" onmouseout=\"setOutColor('Wireless', 'wireless_font')\" onclick='push(this)'/>");
//document.writeln("</td>");
//if((role == 'admin' || role == 'support'))
//{
// /*Voice*/
// document.writeln(" <td width='100' align='center'bgcolor='#AD2721'>");
// document.writeln(" <input id='Voice' type='image' src='Icon_Voice.gif' width=30 heigth=30 onmouseover=\"setOverColor('Voice', 'voice_font')\" onmouseout=\"setOutColor('Voice', 'voice_font')\" onclick='push(this)'/>");
// document.writeln("</td>");
//
//
//}
/*Diagnostic*/
document.writeln(" <td width='100' align='center'bgcolor='#AD2721'>");
document.writeln(" <input id='Diagnostic' type='image' src='Icon_Diagnostic.gif' width=30 heigth=30 onmouseover=\"setOverColor('Diagnostic', 'diag_font')\" onmouseout=\"setOutColor('Diagnostic', 'diag_font')\" onclick='push(this)'/>");
document.writeln("</td>");
/*Management*/
document.writeln("<td width='100' align='center'bgcolor='#AD2721'>");
document.writeln(" <input id='Management' type='image' src='Icon_Management.gif' width=30 heigth=30 onmouseover=\"setOverColor('Management', 'manag_font')\" onmouseout=\"setOutColor('Management', 'manag_font')\" onclick='push(this)'/>");
document.writeln("</td>");
//if(role == admin)
document.writeln("<td bgcolor='#AD2721'> </td>");
//else if(role == user)
// document.writeln("<td width='385'bgcolor='#AD2721'> </td>");
//else if(role == support)
// document.writeln("<td width='385'bgcolor='#AD2721'> </td>");
// done hiding -->
</script>
</tr>
<tr> <script language="javascript">
<!-- hide
//chenyb added for ENKOM 20100610
/*Device Info*/
document.writeln("<td width='100' align='center'bgcolor='#AD2721'>")
document.writeln("<font color='FFFFFF' id='info_font' size=2px face=\"arial\" onmouseover=\"setOverColor('Info', 'info_font')\" onmouseout=\"setOutColor('Info', 'info_font')\"><strong>Info</strong></font>")
document.writeln("</td> ")
/*Quick Start*/
document.writeln("<td width='100' align='center'bgcolor='#AD2721'>")
document.writeln("<font color='FFFFFF' id='qstart_font' size=2px face=\"arial\" onmouseover=\"setOverColor('Quick_Start', 'qstart_font')\" onmouseout=\"setOutColor('Quick_Start', 'qstart_font')\"><strong>Quick Start</strong></font>")
document.writeln("</td> ")
/*Advanced*/
document.writeln("<td width='100' align='center'bgcolor='#AD2721'>")
document.writeln("<font color='FFFFFF' id='advanced_font' size=2px face=\"arial\" onmouseover=\"setOverColor('Advanced', 'advanced_font')\" onmouseout=\"setOutColor('Advanced', 'advanced_font')\"><strong>Advanced</strong></font>")
document.writeln("</td> ")
/*Wireless*/
//document.writeln("<td width='100' align='center'bgcolor='#AD2721'>")
//document.writeln("<font color='FFFFFF' id='wireless_font' size=2px face=\"arial\" onmouseover=\"setOverColor('Wireless', 'wireless_font')\" onmouseout=\"setOutColor('Wireless', 'wireless_font')\"><strong>Wireless</strong></font>")
//document.writeln("</td> ")
//if((role == 'admin' || role == 'support'))
//{
// /*Voice*/
// document.writeln("<td width='100' align='center' bgcolor='#AD2721'>")
// document.writeln("<font color='FFFFFF' id='voice_font' size=2px face=\"arial\" onmouseover=\"setOverColor('Voice', 'voice_font')\" onmouseout=\"setOutColor('Voice', 'voice_font')\" ><strong>Voice<strong></font>")
// document.writeln("</td> ")
//}
/*Diagnostic*/
document.writeln("<td width='100' align='center'bgcolor='#AD2721'>")
document.writeln("<font color='FFFFFF' id='diag_font' size=2px face=\"arial\" onmouseover=\"setOverColor('Diagnostic', 'diag_font')\" onmouseout=\"setOutColor('Diagnostic', 'diag_font')\"><strong>Diagnostic</strong></font>")
document.writeln("</td> ")
/*Managment*/
document.writeln("<td width='100' align='center'bgcolor='#AD2721'>")
document.writeln("<font color='FFFFFF' id='manag_font' size=2px face=\"arial\" onmouseover=\"setOverColor('Managment', 'manag_font')\" onmouseout=\"setOutColor('Managment','manag_font')\"><strong>Management</strong></font>")
document.writeln("</td> ") //if(role == admin)
document.writeln("<td bgcolor='#AD2721'> </td>");
//else if(role == user)
// document.writeln("<td width='385'bgcolor='#AD2721'> </td>");
//else if(role == support)
// document.writeln("<td width='385'bgcolor='#AD2721'> </td>"); // done hiding -->
</script>
case 'Management':
document.getElementById(iid).src = 'Icon_Management_a.gif'; 如果按你说的,那么有这么几种可能:1)我们得保证html的dom加载完毕,再执行js。你可能在dom未加载完毕就执行了你的js代码 2)你的dom对象中没有src属性
错误: 'curCate' 未定义
报了这个错误!你应该知道什么原因吧!