英文:
ng-focus does not work with iframe in AngularJS
问题
ng-focus在AngularJS中无法与iframe一起使用。我可能在这里漏掉了什么?
这是我的代码:
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js"></script>
<iframe src="example.com" tabindex="-1" ng-focus="alert('foo');">
</iframe>
它甚至是否应该工作,或者焦点只能在iframe之外的所有元素上工作?
英文:
ng-focus does not work with iframe in AngularJS. What may I be missing here?
Here is my code:
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js"></script>
<iframe src="example.com" tabindex="-1" ng-focus="alert('foo');">
</iframe>
Is it even supposed to work or will focus work with all elements but the iframe?
答案1
得分: 1
ngFocus支持元素window、input、select、textarea和a,正如文档所述。设置iframe的ngFocus不起作用。
正如文档中的示例所示,这些是ngFocus支持的元素。
<window, input, select, textarea, a
ng-focus="expression">
...
</window, input, select, textarea, a>
还可以查看这篇文章,里面解释得很清楚。
对于window对象的焦点,您可以以以下方式使用$window
包装器:
$window.onfocus = function(){
console.log("focused");
}
英文:
ngFocus is supported for the elements window, input, select, textarea and a as the docs say. Setting ngFocus for an iframe won't work.
As the example in the docs say, those are the supported elements for ngFocus.
<window, input, select, textarea, a
ng-focus="expression">
...
</window, input, select, textarea, a>
Also check this article, there it's pretty clear.
For the window object focus you can use the $window
wrapper in the following way:
$window.onfocus = function(){
console.log("focused");
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论