如何在使用AngularJS将鼠标悬停在另一个div上时更改一个div上的
发布时间:2020-12-17 08:48:47 所属栏目:安全 来源:网络整理
导读:我想在使用AngularJS指令将鼠标悬停在另一个div上时更改一个div的类.这是我到目前为止 http://jsfiddle.net/E8nM5/38/ HMTL div ng-controller="Ctrl" ng-app div ng-class="my-class"This div will change class when one hovers over bottom DIV /div br/
我想在使用AngularJS指令将鼠标悬停在另一个div上时更改一个div的类.这是我到目前为止
http://jsfiddle.net/E8nM5/38/
HMTL <div ng-controller="Ctrl" ng-app> <div ng-class="my-class">This div will change class when one hovers over bottom DIV </div> <br/> <div class="hover-div" ng-mouseenter="my-class = 'highlight'" ng-mouseleave="my-class = 'lowlight'">HOVER OVER ME TO CHANGE THE UPPER DIV's CLASS</div> </div> CSS div.highlight { padding: 10px; background: red; color: white; } div.lowlight { padding: 10px; background: blue; color: white; } div.hover-div { padding: 10px; background: green; color: white; } JS function Ctrl($scope){ } 有任何想法吗?
将my-class更改为myclass(即破折号导致问题).
<div ng-controller="Ctrl" ng-app> <div ng-class="myclass">This div will change class when one hovers over bottom DIV </div> <br/> <div class="hover-div" ng-mouseenter="myclass = 'highlight'" ng-mouseleave="myclass = 'lowlight'">HOVER OVER ME TO CHANGE THE UPPER DIV's CLASS</div> </div> 更新:表达式中不允许my-class的原因是因为AngularJS将短划线视为减号并试图以这种方式解析它.显然,它无法解析语句my – class =’highlight’.不幸的是,在阅读AngularJS解析器代码后,我找不到一种方法来“帮助”它区分破折号和减号. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |