ng-mouseover在Angularjs的禁用按钮上 [英] ng-mouseover on disabled button in Angularjs

查看:87
本文介绍了ng-mouseover在Angularjs的禁用按钮上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当按钮被禁用时,我想使用 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的禁用按钮上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆