3 回答

TA貢獻(xiàn)19條經(jīng)驗 獲得超4個贊
如果用原生的話,可以使用原生的事件委托,在父級上添加事件,當(dāng)事件觸發(fā)的元素是你想要的元素的話改變顏色。

TA貢獻(xiàn)9條經(jīng)驗 獲得超6個贊
js就是用onmouseover和onmouseout事件來操作:
<!DOCTYPE html>
<html>
<head>
? <meta charset="UTF-8">
? <title>Document</title>
? <style>
? #test{width:100px;height:50px;background:red;color: white;font-size:24px;text-align:center;line-height:50px;}
? </style>
</head>
<body>
? <div id='test'>js方法</div>
</body>
<script type="text/javascript">
? var oDiv=document.getElementById('test');
? // 鼠標(biāo)移入事件
? oDiv.onmouseover=function(){
? ? this.style.background='orange';
? ? this.style.color='blue';
? };
? // 鼠標(biāo)移出事件
? oDiv.onmouseout=function(){
? ? this.style.background='red';
? ? this.style.color='white';
? };
</script>
</html>
在事件里面寫入你要修改的屬性就行?。?!
添加回答
舉報