“ng-focus”在AngularJS中无法与iframe一起使用。

huangapple go评论94阅读模式
英文:

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>

fiddle

它甚至是否应该工作,或者焦点只能在iframe之外的所有元素上工作?

英文:

ng-focus does not work with iframe in AngularJS. What may I be missing here?

Here is my code:

&lt;script src=&quot;https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js&quot;&gt;&lt;/script&gt;
&lt;iframe src=&quot;example.com&quot; tabindex=&quot;-1&quot; ng-focus=&quot;alert(&#39;foo&#39;);&quot;&gt;

&lt;/iframe&gt;

fiddle

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支持的元素。

&lt;window, input, select, textarea, a
  ng-focus=&quot;expression&quot;&gt;
...
&lt;/window, input, select, textarea, a&gt;

还可以查看这篇文章,里面解释得很清楚。

对于window对象的焦点,您可以以以下方式使用$window包装器:

$window.onfocus = function(){
   console.log(&quot;focused&quot;);
 }
英文:

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.

&lt;window, input, select, textarea, a
  ng-focus=&quot;expression&quot;&gt;
...
&lt;/window, input, select, textarea, a&gt;

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(&quot;focused&quot;);
 }

huangapple
  • 本文由 发表于 2020年1月3日 22:50:27
  • 转载请务必保留本文链接:https://go.coder-hub.com/59580628.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定