鍍金池/ 問答/HTML/ 怎么才能讓鼠標(biāo)移入.......

怎么才能讓鼠標(biāo)移入.......

加粗文字
怎么才能讓鼠標(biāo)移入sonDIV后parentDIV的height變成200px,且移入parentDIV后height也是200px ,移出parentDIV后height還原

<div id="parent" width="100px" height="50px" >
    <div id="son" width="100px" height="50px"></div>
</div>  
回答
編輯回答
胭脂淚

一:不要寫行內(nèi)樣式,權(quán)重太高,CSS就影響不到了。
二:用css 就能解決
<style>

    #parent{
        height: 50px;
        background: red;
    }
    #son{
        height: 30px;
        background: blue;
    }
    #parent:hover{
        height: 200px;
    }
    #son:hover #parent{
        height: 200px;
    }
</style>
2017年3月30日 09:06
編輯回答
貓館
用mouseenter和mouseleave:
var parent=document.getElementById('parent');
parent.onmouseenter=function(){
    this.style.height=200+'px'
}
parent.onmouseleave=function(){
    this.style.height=50+'px'
}
還有你樣式也寫錯(cuò)了,應(yīng)該是:
 <div id="parent" style="width:100px;height:50px">
2018年7月23日 04:56