我有一个iframe,为了访问父元素,我实现了以下代码:
window.parent.document.getElementById('parentPrice').innerHTML
如何使用jquery得到相同的结果? 更新:或者如何使用jquery访问iFrame父页?
我有一个iframe,为了访问父元素,我实现了以下代码:
window.parent.document.getElementById('parentPrice').innerHTML
如何使用jquery得到相同的结果? 更新:或者如何使用jquery访问iFrame父页?
当前回答
要在iFrame的父类中查找,使用:
$('#parentPrice', window.parent.document).html();
$()包装器的第二个参数是要搜索的上下文。默认为document。
其他回答
你可以使用window从iframe中访问父窗口的元素。父母是这样的:
// using jquery
window.parent.$("#element_id");
也就是:
// pure javascript
window.parent.document.getElementById("element_id");
如果你有多个嵌套iframe并且你想要访问最上面的iframe,那么你可以使用window。上面像这样:
// using jquery
window.top.$("#element_id");
也就是:
// pure javascript
window.top.document.getElementById("element_id");
在父窗口中放置:
<script>
function ifDoneChildFrame(val)
{
$('#parentPrice').html(val);
}
</script>
在iframe SRC文件中放入:
<script>window.parent.ifDoneChildFrame('Your value here');</script>
这对我来说很管用。 在我的情况下,我必须从POPUP JS填充值到父窗口形式。
所以我已经使用$('#ee_id',window.open .document).val(eeID);
优秀的! !
如果你需要在父文档中找到jQuery实例(例如,调用插件提供的实用函数),请使用以下语法之一:
美元window.parent。 window.parent.jQuery
例子:
window.parent.$.modal.close();
jQuery附加到窗口对象,这就是window。父母。
是的,对我来说也很管用。
注意:我们需要使用window.parent.document
$("button", window.parent.document).click(function()
{
alert("Functionality defined by def");
});