急救!!!!!!
<script>
function changestyle(x)
{
for(var i=1;i <=4;i++)
{
var objx=eval( "s "+i);
if(i==x)
{
//document.getElementById( '+objx+ ').className= "on ";
objx.className= "on ";
}
else
//document.getElementById( '+objx+ ').className= " ";
objx.className= " ";
}
// document.getElementById( 's2 ').className= "on ";
}
</script>
<div class= "gNav ">
<ul id= "ulTab ">
<li> <a href= "javascript:; " class= "on " onclick= "changestyle(1) " id= "s1 "> 系统管理 </a> </li>
<li> <a href= "javascript:; " onclick= "changestyle(2) " id= "s2 "> 产品管理 </a> </li>
<li> <a href= "javascript:; " onclick= "changestyle(3) " id= "s3 "> 新闻管理 </a> </li>
<li> <a href= "javascript:; " onclick= "changestyle(4) " id= "s4 "> 会员管理 </a> </li>
</ul>
</div>
以上代码实现点击的时候改变连接的样式,使用objx.className= " ";可以,但是使用document.getElementById( '+objx+ ').className= " ";却不行,因为考虑到兼容火狐,所以要用第二种,也就是代码中注释掉的,getElementById中传参数不行,望高手指点!!!
------解决方案-------------------- <HTML>
<HEAD>
<META http-equiv= "Content-Type " content= "text/html; charset=gb2312 ">
<style>
.on{
background-color:red;
}
</style>
</HEAD>
<BODY>
<script>
function changestyle(x)
{
for(var i=1;i <=4;i++)
{
// var objx=eval( "s "+i);
var objx= "s "+i;
if(i==x)
{
document.getElementById(objx).className= "on ";
// objx.className= "on ";
}
else
document.getElementById(objx).className= " ";
//objx.className= " ";
}
// document.getElementById( 's2 ').className= "on ";
}
</script>
<div class= "gNav ">
<ul id= "ulTab ">
<li> <a href= "javascript:; " class= "on " onclick= "changestyle(1) " id= "s1 "> 系统管理 </a> </li>
<li> <a href= "javascript:; " onclick= "changestyle(2) " id= "s2 "> 产品管理 </a> </li>
<li> <a href= "javascript:; " onclick= "changestyle(3) " id= "s3 "> 新闻管理 </a> </li>
<li> <a href= "javascript:; " onclick= "changestyle(4) " id= "s4 "> 会员管理 </a> </li>
</ul>
</div>
</BODY>
</HTML>