我有一个iframe,为了访问父元素,我实现了以下代码:
window.parent.document.getElementById('parentPrice').innerHTML
如何使用jquery得到相同的结果? 更新:或者如何使用jquery访问iFrame父页?
我有一个iframe,为了访问父元素,我实现了以下代码:
window.parent.document.getElementById('parentPrice').innerHTML
如何使用jquery得到相同的结果? 更新:或者如何使用jquery访问iFrame父页?
当前回答
是的,对我来说也很管用。
注意:我们需要使用window.parent.document
$("button", window.parent.document).click(function()
{
alert("Functionality defined by def");
});
其他回答
如何使用jquery访问iFrame父页面
window.parent.document。
jQuery是JavaScript之上的库,而不是JavaScript的完全替代品。您不必将每一个JavaScript表达式都替换为包含$的表达式。
是的,对我来说也很管用。
注意:我们需要使用window.parent.document
$("button", window.parent.document).click(function()
{
alert("Functionality defined by def");
});
在父窗口中放置:
<script>
function ifDoneChildFrame(val)
{
$('#parentPrice').html(val);
}
</script>
在iframe SRC文件中放入:
<script>window.parent.ifDoneChildFrame('Your value here');</script>
如果你需要在父文档中找到jQuery实例(例如,调用插件提供的实用函数),请使用以下语法之一:
美元window.parent。 window.parent.jQuery
例子:
window.parent.$.modal.close();
jQuery附加到窗口对象,这就是window。父母。
要在iFrame的父类中查找,使用:
$('#parentPrice', window.parent.document).html();
$()包装器的第二个参数是要搜索的上下文。默认为document。