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

前端之家收集整理的这篇文章主要介绍了html5 – 在Internet Explorer中使用自动对焦时,模态中的奇怪光标位置前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
在IE中使用自动对焦时,我遇到光标放置问题.图像应清楚地显示问题.

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

我如何使IE表现?

AngularJS(也可在plunker中获得)

  1. app.directive('autofocus',[
  2. '$timeout',function($timeout) {
  3. return function(scope,elem,attr) {
  4. scope.$on('autofocus',function(e) {
  5. $timeout(function() {
  6. elem[0].focus();
  7. });
  8. });
  9. };
  10. }
  11. ]);
  12.  
  13. /* https://stackoverflow.com/questions/14833326/how-to-set-focus-in-angularjs */
  14. app.factory('autofocus',['$rootScope','$timeout',function($rootScope,$timeout) {
  15. return function() {
  16. $timeout(function() {
  17. $rootScope.$broadcast('autofocus');
  18. });
  19. };
  20. }]);
  21.  
  22. app.config(['$stateProvider',function ($stateProvider) {
  23. $stateProvider.state('main',{
  24. url: '/main'
  25. });
  26. }]);
  27.  
  28. app.config(['$stateProvider',function ($stateProvider) {
  29. $stateProvider.state('main.modal',{
  30. url: '/modal',onEnter: ['$state','$stateParams','$modal','autofocus',function ($state,$stateParams,$modal,autofocus) {
  31. var instance = $modal.open({
  32. templateUrl: 'modal.html'
  33. });
  34. instance.result.then(function () {
  35. // OK
  36. // GOTO parent state
  37. $state.go('^');
  38. },function () {
  39. // Cancel
  40. // GOTO parent state
  41. $state.go('^');
  42. });
  43. instance.opened.then(function() {
  44. autofocus();
  45. });
  46. }
  47. ]
  48. });
  49. }]);

标记

  1. <form>
  2. <div class="modal-header">
  3. <h3 class="modal-title">I'm a modal!</h3>
  4. </div>
  5. <div class="modal-body">
  6. <input type="text" name="foo" autofocus>
  7. <br>
  8. <input type="text" name="bar">
  9. </div>
  10. <div class="modal-footer">
  11. <button type="submit" class="btn btn-primary">OK</button>
  12. <button type="button" class="btn btn-warning" ng-click="$dismiss()">Cancel</button>
  13. </div>
  14. </form>

解决方法

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

猜你在找的HTML5相关文章