首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >用于隐藏HTML Tampermonkey的按钮

用于隐藏HTML Tampermonkey的按钮
EN

Stack Overflow用户
提问于 2020-03-09 00:00:22
回答 1查看 54关注 0票数 0

您好,我正在尝试让一个代码工作,其中,如果你点击一个按钮,它将隐藏一段HTML,当你再次点击它时,它会再次显示。

代码语言:javascript
复制
    let newImg4 = document.createElement("img");
newImg4.src = "https://image.flaticon.com/icons/png/512/63/63801.png";
newImg4.style = `position: absolute; bottom: 290px; right: 20px; z-index: 100000; width: 50px; height: 50px; cursor: pointer;`;
document.body.prepend(newImg4);
newImg4.addEventListener("click", () => {
      let w = HIDE HTML HERE!("<iframe src="https://discordapp.com/widget?id=yesihavetheidijuswanttokeepittomyselffornow&theme=dark" width="350" height="500" allowtransparency="true" frameborder="0"></iframe>");
});

任何帮助都是非常有价值的!提前谢谢。

EN

回答 1

Stack Overflow用户

发布于 2020-03-18 20:00:49

您必须首先获取iframe (来自Hisham的注释遗漏了这一点),然后将其显示样式设置为none。

代码语言:javascript
复制
let newImg4 = document.createElement("img");
newImg4.src = "https://image.flaticon.com/icons/png/512/63/63801.png";
newImg4.style = `position: absolute; bottom: 290px; right: 20px; z-index: 100000; width: 50px; height: 50px; cursor: pointer;`;
document.body.prepend(newImg4);
var elem = document.getElementsByTagName("iframe")[0];
newImg4.addEventListener("click", () => { if (elem.style.display === "none") { elem.style.display = "block"; } else { elem.style.display = "none"; } });
代码语言:javascript
复制
<iframe src="https://discordapp.com/widget?id=yesihavetheidijuswanttokeepittomyselffornow&theme=dark" width="350" height="500" allowtransparency="true" frameborder="0"></iframe>

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60589289

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档