【问题标题】:ng-click with Bootstrap Rating使用 Bootstrap Rating 进行 ng-click
【发布时间】:2014-04-25 06:30:16
【问题描述】:

我有一个 Bootstrap Rating 组件,我必须使用 on-leave 方法来调用我的 javascript 函数。除了在 IE 中,所有其他浏览器也会在点击事件时执行离开功能。但是在 IE 中,在我离开 stars'div 之前,不会调用该函数。我什至不能使用 ng-click,因为 Bootstrap Rating 组件不支持它(我的角度版本是 1.1.5)

<div id="ratingDiv{{$index}}" style="display:none;" class="ratingDivClass">
<span class="ratingPoorClass">Poor</span>
<rating id="rateStars" onclick="$jq('#loader').show();" value="userRating" max="5" 
on-hover="hoveringOver(value)" 
on-leave="saveRating(message.id,userRating,$index,message.entity);"></rating>
<span class="ratingGoodClass">Very Good</span>
</div>

问题:在 IE 中,直到我离开 div 函数才被调用

试过了:

  1. 在点击而不是离开时调用函数:它不传递范围相关参数
  2. 点击 div 时触发 mouseleave() 方法:无效:(

如果有人对此有任何解决方案,请告诉我。

【问题讨论】:

  • 你使用 AngularJS 吗?因为这看起来像是 Angular、标准 JS 和 jquery 的混合体。 angular有自己的ngMouseleave directive
  • 是的,我使用 Angular JS...但是 ngMouseleave 对我没有帮助,因为我想要一个点击功能。我想在 Rating 组件的点击事件上触发函数调用

标签: javascript jquery angularjs twitter-bootstrap


【解决方案1】:

我在使用 angularjs 和 IE 时遇到过类似的问题。在我的情况下,按键不起作用,解决方案是使用按键事件(请参阅http://api.jquery.com/keyup/)。

在您的情况下,您可能遇到此问题https://github.com/angular/angular.js/issues/1277

我不熟悉上面的'on-leave',但你可以试试jquery blur 方法:https://api.jquery.com/blur/

【讨论】:

    【解决方案2】:

    基于ng-mouseleave的文档,你可以试试下面的代码。

    在我的上一个项目中,我使用下面的 IE8 代码来支持某些功能.. 你也可以试试请假。

    <!--[if lte IE 8]>
      <script>
        document.createElement('ng-include');
        document.createElement('ng-pluralize');
        document.createElement('ng-view');   
        document.createElement('alert');
        document.createElement('progress');
        document.createElement('ng-mouseleave');// try this
    
        // Optionally these for CSS
        document.createElement('ng:include');
        document.createElement('ng:pluralize');
        document.createElement('ng:view');
      </script>
    <![endif]-->
    

    【讨论】:

    • 谢谢大家!!我尝试了上述解决方案,但不知何故无法实现所需。所以我已经完成了我脑海中的最后一个工作。在整个 html 上具有单击功能并验证是否单击了评级组件,然后执行我的代码。我希望 bootstrap 在未来的版本中也能支持点击!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-12-23
    • 2017-08-07
    • 1970-01-01
    • 2015-03-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多