问题描述
当按钮被禁用时,我想使用 mouseover
。如果 ng-disabled =false
,下面的代码 mouseover
会起作用,但如果 ng-disabled =true
。
I want to use mouseover
when the button is disabled. In the below code mouseover
will work if ng-disabled="false"
but it won't work if ng-disabled="true"
.
<body ng-app="ngAnimate">
<button ng-disabled="true" ng-mouseover="show=true" ng-mouseleave="show = false">
Mouseover
</button>
<div>
Show:
<span class="test" ng-show="show">
I show up when your mouse enter on button
</span>
</div>
</body>
推荐答案
这不是可能的。实际上它与Angular没有任何关系。当浏览器不应该在禁用表单控件上触发鼠标事件,onclick等事件时,这是预期的行为。所以你不能直接这样做。
It's not possbile. Actually it has nothing to do with Angular. It's expected behaviour when browsers are not supposed to fire onmouseover, onclick, etc. events on disabled form controls. So you can't do it directly.
无法直接执行 - 这意味着您可以将mouseover绑定到包装容器上不会有这个限制。然后,如果需要,您需要控制操作并仅在禁用标志 true
或 false
时继续。
Can't do it directly - meaning, that you can bind mouseover even to wrapping container which would not have this limitation. Then you would need to control action and proceed only if disabled flag is true
or false
if you need.
这就是说,你可能不应该试图解决这个问题。在所有禁用的含义之后,表单UX透视禁用控件不应该是可交互的。
That being said, you should probably not try to workaround this behaviour. Form UX perspective disabled control should not be interaction-able, after all that's what disabled means.
这篇关于ng-mouseover在Angularjs的禁用按钮上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!