关于JS代码。。请高手帮我翻译下

2024-11-26 10:36:25
推荐回答(2个)
回答1:

/*这两段代码的总体方法是实现菜单的类似于滑片技术功能*/

function g(o){return document.getElementById(o);}/*取得o的属性*/

function huamen(n){

for(var i=1;i<=6;i++){

g('hm'+i).className='huam_h1';/*hm1,hm2,hm3,hm4,hm5,hm6的样式名称改为huam_h1样式,以下代码类扒*/

g('huam_n0'+i).className='undis';}

g('huam_n0'+n).className='dis';

g('hm'+n).className='huam_h2';}

/*

huamen(1)则为 huam_n01的样式为dis,hm1的样式为huam_h2,其余hm2,hm3,hm4,hm5,hm6的样式都为huam_h1,

huam_n02,huam_n03,huam_n04,huam_n05,huam_n06的样式都为undis

*/

实现效果图如下:

回答2:

//事件g中有参数o(o是个ID属性)
function
g(o){
//返回这个ID
return
document.getElementById(o);
}
//事件huamen有参数n(是个数字)
function
huamen(n){
//循环从1开始到6
for(var
i=1;i<=6;i++){
//调用了g这个事件传参'hm'+i(i在1-6),并给'hm'+i
(ID属性)的class属性赋值
g('hm'+i).className='huam_h1';
//同上
g('huam_n0'+i).className='undis';
}
//调用了g这个事件传参'huam_n0'+n,并给class属性赋值
g('huam_n0'+n).className='dis';
g('hm'+n).className='huam_h2';
}