【问题标题】:How to remove focus from ui-select after selecting an option选择选项后如何从 ui-select 中移除焦点
【发布时间】:2016-06-08 02:36:06
【问题描述】:

一旦用户使用鼠标单击选择了一个选项并进入开始搜索,我需要从 ui-select 输入中移除焦点。现在发生的情况是焦点仍然在 select 上,因此在单击 enter 时会打开下拉列表。

  <ui-select id= "country" ng-model="ctry" name= "country"  theme="bootstrap">
      <ui-select-match >{{text || $select.selected.id}}</ui-select-match>
          <ui-select-choices repeat="countryL in countryLookup | filter: $select.search">
             <div ng-bind-html="countryL.id | highlight: $select.search"></div>
                <small ng-bind-html="countryL.name | highlight: $select.search"></small>
       </ui-select-choices>

【问题讨论】:

    标签: angularjs ui-select


    【解决方案1】:

    将 on-select="onSelected($item)" 添加到您的 ui-select 和控制器中:

    $scope.onSelected = function (selectedItem) {
        setTimeout(function(){
            $(':focus').blur();
        })
    }
    

    或在控制器中使用 $timeout

    【讨论】:

    • 当我们点击外部而不选择任何东西时,这不起作用。通过设置 skip-focusser="true" 它将适用于两种情况。
    【解决方案2】:

    从 v0.14.9 版本开始,您可以将 skip-focusser 设置为 true 以在选择项目后跳过焦点。

    【讨论】:

      【解决方案3】:

      以下对我有用;

      $timeout(function() {
          angular.element(document.activeElement).blur();
      });
      

      $timeout(function() {
          angular.element($document[0].activeElement).blur();
      });
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2011-11-09
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-06-22
        • 2015-07-07
        相关资源
        最近更新 更多