javascript - 从父标签中通过 id 获取元素

标签 javascript jquery html iframe

我的 DOM 如下。

<html><head>...</head><body><script>...</script>
<iframe id="frame">
    #document
    <html>...</html> <!-- 2 -->
</iframe>
</body>
</html>

我正在 iframe 中绑定(bind)部分内容(即 html 2)。在 html_2 部分中,我正在调用 document.ready 使用 getElementById 获取 iframeid,但我得到。如何获取iframe的id等属性值?

最佳答案

我这样做如下,

$("#iframe", parent.document).attr("id");

顺便说一句,感谢所有通过宝贵意见回答和帮助我的人。

关于javascript - 从父标签中通过 id 获取元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41157288/

相关文章:

javascript - 嵌套函数组件ReactJS

jquery - 在没有循环的情况下识别 jquery dom 元素

javascript - 具有多层图像的产品图像缩放

Javascript 事件 'mouseenter' 第一次触发两次 - Meteor

javascript - 消除全屏浏览器和大屏幕(49 英寸)上页脚下的空白

php - PHP 中的 Javascript 正则表达式相当于什么?

php - 将动态 jQuery post 传递给 PHP

javascript - Paypal 点击按钮不适用于 safari

html - 边界与 li 的 child 和子 child 重叠

javascript - 在 html 编辑器中允许 anchor 标记安全吗?