gpt4 book ai didi

javascript - 我需要一个脚本来在开关按钮打开时复制 标签,并在开关按钮关闭时删除 标签

转载 作者:太空宇宙 更新时间:2023-11-04 03:37:19 31 4
gpt4 key购买 nike

我需要一个脚本来复制<img>当开关按钮打开时标记,当开关按钮关闭时删除标记。我需要一个简单的方法。这是开关按钮:

<div class="onoffswitch">
<input type="checkbox" name="onoffswitch" class="onoffswitch-checkbox" id="myonoffswitch" checked>
<label class="onoffswitch-label" for="myonoffswitch">
<span class="onoffswitch-inner"></span>
<span class="onoffswitch-switch"></span>
</label>
</div>

我试过这个:

<script language="javascript">
var changeImage = function(){
img1="image/rez.jpg";
switch(document.getElementById('myonoffswitch').src){
case img1:
document.getElementById("myonoffswitch").src=img1;
break;
default:
document.getElementById("chango").src=img1;
break;
};
};
</script>

最佳答案

如果你只想显示/隐藏图像,你可以使用如下简单的 CSS。

CSS

#myonoffswitch ~ img
{
display:none;
}
#myonoffswitch:checked ~ img
{
display:block;
}

HTML

 <div class="onoffswitch">
<input type="checkbox" name="onoffswitch" class="onoffswitch-checkbox" id="myonoffswitch" checked>
<label class="onoffswitch-label" for="myonoffswitch">
<span class="onoffswitch-inner"></span>
<span class="onoffswitch-switch"></span>
</label>
<img src="http://isc.stuorg.iastate.edu/wp-content/uploads/sample.jpg" />
</div>

DEMO

关于javascript - 我需要一个脚本来在开关按钮打开时复制 <img> 标签,并在开关按钮关闭时删除 <img> 标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25377010/

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