ng-focus和ng-blur在选择的DOM上不起作用 [英] ng-focus and ng-blur do not work on select DOM

查看:96
本文介绍了ng-focus和ng-blur在选择的DOM上不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先,我创建一个简单的示例来查看ng-focus和ng-blur是否在select上拖动,然后是我的实际代码,我找不到第二个为什么不起作用的原因:

First I create a simple example to see if the ng-focus and ng-blur are driggered on select, and then are my actual code, I cannot find why the second do not work:

<div ng-app ng-init="focus=false;blur=false;active=false"> 
<select ng-focus="focus=true;blur=false;" ng-blur="blur=true;focus=false;">
    <option>sdasdsa</option>
    <option>dsadsads</option>
</select>
    <input type="text" ng-class="{ myFocus: focus, myBlur: blur }">
</div>

    <br>
         <br>
              <br>
                   <br>

<div class="search-input" ng-init="focus=false;blur=false;active=false">
    <input type="text" ng-class="{ myFocus: focus, myBlur: blur }">
            <div class="selects">
              <div class="icon fluid select">
                <i  ng-class="{'large svg guests icon':rooms==2, 'large svg guest icon':rooms==1,'active':{{focus}}}"></i>
                <label ng-click="closeCalendar()">
                  <select ng-model="rooms" name="rooms" class="fluid" name="rooms" focus-parent selecter required ng-focus="focus=true;blur=false;" ng-blur="blur=true;focus=false;">
                      <option value="1">Einzelzimmer</option>
                      <option value="2">Doppelzimmer</option>
                  </select>
                </label>
              </div>
            </div>
          </div>

http://jsfiddle.net/deathhell/UTn5y/2/

推荐答案

您不能将ng-focusng-blur用于select元素.

在替代方案是使用选择一个新的选项的时候,会触发.

The alternative is to use ng-change which will trigger when a new option is selected.

请注意,对于ng-change,还必须具有ng-model.要求.

Note that with ng-change, it is required to have ng-model as well.

http://jsfiddle.net/5bv2Z/

这篇关于ng-focus和ng-blur在选择的DOM上不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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