gpt4 book ai didi

javascript - 如何设置扩展菜单在页面加载时关闭

转载 作者:行者123 更新时间:2023-11-28 13:39:48 24 4
gpt4 key购买 nike

我有一个点击展开的 div,但我不知道如何将它设置为在页面关闭时不展开?

        <script>
function toggleDiv(id1,id2) {
var tag = document.getElementById(id1).style;
var tagicon = document.getElementById(id2);

if(tag.display == "none") {
tag.display = "block";
tagicon.innerHTML = "&nbsp;-&nbsp;";
} else {
tag.display = "none";
tagicon.innerHTML = "&nbsp;+&nbsp;";
}
}
</script>

和 HTML:

<div class="title" onClick="javascript:toggleDiv('content1','icon1');">
<span style="float:left">Options</span>
<span id="icon1" style="float:right">&nbsp;-&nbsp;</span>
</div>
<div id="content1" class="item">
<div><input type="button" onclick="changeBG('#FF0097')" value="Magenta"/></div>
<div><input type="button" onclick="changeBG('#A200FF ')" value="Purple"/></div>
<div><input type="button" onclick="changeBG('#00ABA9')" value="Teal"/></div>
<div><input type="button" onclick="changeBG('#8CBF26')" value="Lime"/></div>
<div><input type="button" onclick="changeBG('#F09609')" value="Orange"/></div>
<div><input type="button" onclick="changeBG('#1BA1E2')" value="Blue"/></div>
<div><input type="button" onclick="changeBG('#E51400')" value="Red"/></div>
<div><input type="button" onclick="changeBG('#339933')" value="Green"/></div>
</div>

CSS incase 你需要它:

.title {
padding:5px;
border:1px solid #CCCCCC;
font:15px arial;
width:100px;
cursor:pointer;
height:20px;
}

.item {
padding:5px;
border:1px solid #CCCCCC;
font:12px verdana;
width:100px;
}

.item div {
border-bottom:1px solid #CCCCCC;
padding:5px;
}

.button {
border:1px solid #CCCCCC;
padding:5px;
cursor: pointer;
}

如您所见,下拉菜单允许用户更改网站的背景颜色。我想知道是否可以创建一个 cookie 来存储更改,以便在用户选择颜色之前它不会首先默认为白色背景?

谢谢堆栈溢出(:

感谢所有帮助。

最佳答案

我确定您的 html 页面上有正文。只需添加如下所述的功能。有用。我测试过

<body onLoad="toggleDiv('content1','icon1')">

关于javascript - 如何设置扩展菜单在页面加载时关闭,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12548737/

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