gpt4 book ai didi

javascript - 从新打开的窗口jquery中删除一个节点

转载 作者:行者123 更新时间:2023-11-29 17:15:56 24 4
gpt4 key购买 nike

我正在尝试使用以下代码打开一个新窗口。

$("#printBtn").on("click", function () {
var w = window.open(this.href, "myWindowName", "width=800, height=600");
$(w.document.body).children(".top-fixed-nav").remove();
return false;
});

我遇到的问题是新窗口打开时确实显示了所需的输出,但我使用的是 $(w.document.body).children(".top-fixed-nav") .remove(); 不工作即 .top-fixed-nav 不删除。我也尝试将它绑定(bind)到 ready 事件

$("#printBtn").on("click", function () {
var w = window.open(this.href, "myWindowName", "width=800, height=600");
$(w).ready(function(){
$(w.document.body).children(".top-fixed-nav").remove();
});
return false;
});

但这也没有用。谁能告诉我,我做错了什么?

更新

试过这个:

$("#printBtn").on("click", function () {
var w = window.open(this.href, "myWindowName", "width=800, height=600");
// $(w.document).ready(function(){
// and $(w.document).load(function(){
$(w.document.body).children(".top-fixed-nav").remove();
});
return false;
});

这两个都不起作用。

最佳答案

$("#printBtn").on("click", function () {
var w = window.open(this.href, "myWindowName", "width=800, height=600");
$(w).on("load", function(){
$(w.document.body).children(".top-fixed-nav").remove();
});
return false;
});

试试这个,因为 onload 方法适用于窗口而不是文档。

关于javascript - 从新打开的窗口jquery中删除一个节点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17940843/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com