我有一个iframe,为了访问父元素,我实现了以下代码:

window.parent.document.getElementById('parentPrice').innerHTML

如何使用jquery得到相同的结果? 更新:或者如何使用jquery访问iFrame父页?


当前回答

如何使用jquery访问iFrame父页面

window.parent.document。

jQuery是JavaScript之上的库,而不是JavaScript的完全替代品。您不必将每一个JavaScript表达式都替换为包含$的表达式。

其他回答

要在iFrame的父类中查找,使用:

$('#parentPrice', window.parent.document).html();

$()包装器的第二个参数是要搜索的上下文。默认为document。

如何使用jquery访问iFrame父页面

window.parent.document。

jQuery是JavaScript之上的库,而不是JavaScript的完全替代品。您不必将每一个JavaScript表达式都替换为包含$的表达式。

在父窗口中放置:

<script>
function ifDoneChildFrame(val)
{
   $('#parentPrice').html(val);
}
</script>

在iframe SRC文件中放入:

<script>window.parent.ifDoneChildFrame('Your value here');</script>

是的,对我来说也很管用。

注意:我们需要使用window.parent.document

    $("button", window.parent.document).click(function()
    {
        alert("Functionality defined by def");
    });

这对我来说很管用。 在我的情况下,我必须从POPUP JS填充值到父窗口形式。

所以我已经使用$('#ee_id',window.open .document).val(eeID);

优秀的! !