首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > JavaScript >

html一个简单的有关问题

2013-04-20 
html一个简单的问题我想给一个样式加hover例如.a1{height:20pxwidth:20px}.a2{height:120pxwidth:120px

html一个简单的问题
我想给一个样式加hover

例如

.a1
{
  height:20px;
  width:20px;
}
.a2
{
  height:120px;
  width:120px;
}

鼠标停在a1上时,a2发生改变
怎么写啊 HTML 鼠标 hover
[解决办法]


.a1{
    height:60px;
    width:60px;
    border:1px solid #000;
}
.a2{
    height:20px;
    border:1px solid #000;
    width:20px;
}

.a1:hover .a2{
    height:40px;
    width:40px;
}


a2要是在a1里面可以这么写,要是在外面的话只能写JS来解决了


var a1 = document.getElementById('a1')
var a2 = document.getElementById('a2')
a1.onmouseover = function(){
    a2.className += 'a1hover';
}
a1.onmouseout = function(){
    var clses = a2.className;
    clses = clses.split(' ');
    var len = clses.length;
    for(var i=0;i<len;i++){
        if(clses[i] && clses[i]=='a1hover'){
            clses.splice(i,1);
        }
    }
    a2.className = clses.join(' ');
}

热点排行