JS代码:var city = document.getElementsByClassName("city-name");var city_ico = document.getElementsByClassName("ico-city");var city_list = document.getElementsByClassName("city-list")//ico翻转function ico_rotate(){ var classVal = city_ico[0].getAttribute("class"); var city_hover = document.getElementsByClassName("city-hover"); //判断city是否存在 if(city_hover.length !== 0){ classVal = classVal.replace(" city-hover"," "); city_ico[0].setAttribute("class",classVal); }else{ classVal = classVal.concat(" city-hover"); city_ico[0].setAttribute("class",classVal); }};//显示隐藏function toggle(className,num){ var list = className[num].style.display; if(list == "block"){ className[num].style.display = "none"; }else{ className[num].style.display = "block"; }city[0].addEventListener("mouseover",ico_rotate);city[0].addEventListener("mouseout",ico_rotate);city[0].addEventListener("mouseover",function(){ toggle(city_list,0);});city[0].addEventListener("mouseout",function(){ toggle(city_list,0);});
添加回答
举报
0/150
提交
取消