这可能是一个愚蠢的问题,但是当我使用 iframe 时,如果您单击该框架,特定方面(由 iframe 使用的 html 文件中的事件监听器控制)可用。如果您在 iframe 外部单击,它将失去对这些控件和事件监听器的访问权限。有没有办法使 iframe 已被点击?。抱歉措辞不当,但我还没有找到一种方法来做到这一点,有什么想法吗?
最佳答案
<iframe id="iframe" autofocus="true" src="page.html"></iframe>
<script>
document.getElementById('iframe').focus();
</script>
HTML5 中的 autofocus 属性也可以强制元素的焦点。在此示例中,它是多余的。
关于javascript - 确保立即选择 iframe,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8751734/