这样写为什么有问题不能执行?

来源:百度知道 编辑:UC知道 时间:2024/09/22 13:41:21
<SCRIPT language="javascript">
function topLink(){
var add = top.location;
add = add.toString();
tmp=add.substring(add.indexOf("index_")+1,add.length) ;
tmp=tmp.substring(0,4);
}
switch(tmp){
case news:
document.getElementById("menu_top2").className="current";
break;
case gryw:
document.getElementById("menu_top3").className="current";
break;
case gsyw:
document.getElementById("menu_top4").className="current";
break;
case card:
document.getElementById("menu_top5").className="current";
break;
case gjyw:
document.getElementById("menu_top6").className="current";
break;
case dzyh:
document.getElementById("menu_top7").className="current";
break;
case gytl:
document.getElementById("menu_top8").clas

tmp变量放在函数topLink内部,只有调用了函数才能执行,才会给tmp变量赋值
可以在函数后面调用一下,topLink();

可以帮忙把上面的代码 改一下吗?谢谢

function topLink(){
var add = top.location;
add = add.toString();
tmp=add.substring(add.indexOf("index_")+1,add.length) ;
tmp=tmp.substring(0,4);

switch(tmp){
case news:
document.getElementById("menu_top2").className="current";
break;
case gryw:
document.getElementById("menu_top3").className="current";
break;
case gsyw:
document.getElementById("menu_top4").className="current";
break;
case card:
document.getElementById("menu_top5").className="current";
break;
case gjyw:
document.getElementById("menu_top6").className="current";
break;
case dzyh:
document.getElementById("menu_top7").className=&q