用JS怎么实现菜单栏鼠标移入时背景色、字体颜色改变(在下面的代码中修改)
多级菜单 JSul {list-style: none;}.top-nav{font-size: 12px;font-weight: 700;}.top-nav li {float: left;margin-right: 1px;}.top-nav li a {display: block;width: 80px;line-height: 20px;text-decoration: none;background: #ddd;color: #666;text-align: center;}.top-nav li ul {display: none;padding: 0;position: relative; width: 80px;}.top-nav li ul li ul {position: absolute; top: 0;left: 81px; }.top-nav li a:hover {background: #900;color: white; } <script>window.onload=function(){var Lis=document.getElementsByTagName("li");for(var i=0;i |
免责声明:本内容仅代表回答会员见解不代表天盟观点,请谨慎对待。
版权声明:作者保留权利,不代表天盟立场。
|
|
|
|
如果用原生的话,可以使用原生的事件委托,在父级上添加事件,当事件触发的元素是你想要的元素的话改变颜色。 |
|
|
|
|
js就是用onmouseover和onmouseout事件来操作:
Document
#test{width:100px;height:50px;background:red;color: white;font-size:24px;text-align:center;line-height:50px;}
js方法
在事件里面写入你要修改的属性就行!!! |
|
|
|
|