【发布时间】:2015-02-14 04:27:09
【问题描述】:
我正在使用 JQVMap,我的代码取决于您单击的状态,它会在地图下方的单个 div 中显示有关该状态的信息。但是,我觉得有一种简化、更有效的方法来设置此代码,因此不会有太多重复,尤其是在我开始添加更多状态时。有吗?
switch(code){
case"tx":
$('#info-children').children(':not(#info-tx)').hide("slow");
$('#info-children').children('#info-tx').show("slow");
break;
case"il":
$('#info-children').children(':not(#info-il)').hide("slow");
$('#info-children').children('#info-il').show("slow");
break;
case"fl":
$('#info-children').children(':not(#info-fl)').hide("slow");
$('#info-children').children('#info-fl').show("slow");
break;
case"ga":
$('#info-children').children(':not(#info-ga)').hide("slow");
$('#info-children').children('#info-ga').show("slow");
break;
case"pa":
$('#info-children').children(':not(#info-pa)').hide("slow");
$('#info-children').children('#info-pa').show("slow");
break;
default:
$('#state-name').html(region);
$('#info-children').children(':not(#info-uhoh)').hide("slow");
$('#info-children').children('#info-uhoh').show("slow");
}
【问题讨论】:
标签: javascript jquery switch-statement