gpt4 book ai didi

javascript - 使用 Javascript,如何更改不同 HTML 页面上的 CSS 显示属性

转载 作者:行者123 更新时间:2023-11-28 13:31:37 25 4
gpt4 key购买 nike

所以,我想更改其中一个 div 的显示样式,这是我的 javascript 中的代码:

document.getElementById("header1").style.display='none';

现在的问题是……header1 是不同页面上的一个 div id,但我想通过在当前页面上选择一个选项来影响它。我该怎么做才能在进入下一页时隐藏 header1?

提前致谢!

最佳答案

您不能更改尚未加载到浏览器中的元素的属性。您必须使用 cookie 或查询字符串来告诉您在加载页面时隐藏该元素。

编辑

您可以使用以下 javascript 重定向到新页面。注意:? 之后的所有内容都是查询字符串的一部分。

// Redirect without querystring
window.location = "http://www.mySite.com/default.html"

// Redirect with querystring
window.location = "http://www.mySite.com/default.html?hide=true"

// Redirect with multiple values in querystring
window.location = "http://www.mySite.com/default.html?hide=true&test=1"

查看 get-query-string-values-in-javascript查看如何通过 javascript 检索查询字符串值。

关于javascript - 使用 Javascript,如何更改不同 HTML 页面上的 CSS 显示属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11436564/

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