微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

html5 – 在Internet Explorer中使用自动对焦时,模态中的奇怪光标位置

在IE中使用自动对焦时,我遇到光标放置问题.图像应清楚地显示问题.

幸运的是,我已经能够在plunker中重现这一点.我已经将它剥离到了基本要素,所以它应该很容易看到发生了什么.

我如何使IE表现?

AngularJS(也可在plunker中获得)

app.directive('autofocus',[
  '$timeout',function($timeout) {
      return function(scope,elem,attr) {
          scope.$on('autofocus',function(e) {
              $timeout(function() {
                  elem[0].focus();
              });
          });
      };
  }
]);

/* https://stackoverflow.com/questions/14833326/how-to-set-focus-in-angularjs */
app.factory('autofocus',['$rootScope','$timeout',function($rootScope,$timeout) {
  return function() {
      $timeout(function() {
          $rootScope.$broadcast('autofocus');
      });
  };
}]);

app.config(['$stateProvider',function ($stateProvider) {
    $stateProvider.state('main',{
        url: '/main'
    });
}]);

app.config(['$stateProvider',function ($stateProvider) {
    $stateProvider.state('main.modal',{
        url: '/modal',onEnter: ['$state','$stateParams','$modal','autofocus',function ($state,$stateParams,$modal,autofocus) {
                var instance = $modal.open({
                    templateUrl: 'modal.html'
                });
                instance.result.then(function () {
                    // OK
                    // GOTO parent state
                    $state.go('^');
                },function () {
                    // Cancel
                    // GOTO parent state
                    $state.go('^');
                });
                instance.opened.then(function() {
                  autofocus();
                });
            }
        ]
    });
}]);

标记

<form>
  <div class="modal-header">
      <h3 class="modal-title">I'm a modal!</h3>
  </div>
  <div class="modal-body">
      <input type="text" name="foo" autofocus>
      <br>
      <input type="text" name="bar">
  </div>
  <div class="modal-footer">
      <button type="submit" class="btn btn-primary">OK</button>
      <button type="button" class="btn btn-warning" ng-click="$dismiss()">Cancel</button>
  </div>
</form>

解决方法

看起来我可能是“幻灯片” – 动画应该受到指责.
我设法通过强制模态淡入而不滑动来修复此问题,方法添加“windowClass:modal fade in”,如下所示:
app.config(['$stateProvider',autofocus) {
                var instance = $modal.open({
                    templateUrl: 'modal.html',windowClass: 'modal fade in'
                });
                instance.result.then(function () {
                    // OK
                    // GOTO parent state
                    $state.go('^');
                },function () {
                    // Cancel
                    // GOTO parent state
                    $state.go('^');
                });
                instance.opened.then(function() {
                  autofocus();
                });
            }
        ]
    });
}]);

原文地址:https://www.jb51.cc/html5/168253.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。