gpt4 book ai didi

javascript - HTML 在点击时显示图像

转载 作者:太空宇宙 更新时间:2023-11-03 22:49:14 24 4
gpt4 key购买 nike

我有一个带有图像的 HTML 页面(想用作按钮)和一些我设置为通过 CSS visibility: hidden 不可见的图像。我想在单击此“图片‘w-click.png’”时显示另一张图片。

所以,标记到其他一些图像。在我的例子中,我希望点击“w-click.png”来调用 JavaScript 来显示图像。

我发现一键显示一个图像,但我想要一键显示多张图像....

编辑:这是我的代码

<img src="IMAGE/w-click.png" style="z-index:200; margin-left:6680px; position:relative; width:700px; margin-top:-100px; padding:0; position:absolute; " />

<div class="invisible-livingroom">
<img src="IMAGE/w-clock.png" style="position:absolute; margin-left:1200px; filter:brightness(1.3);visibility:hidden; " />
<img src="IMAGE/w-stand.png" style="position:absolute; margin-left:1830px; margin-top:120px;filter:brightness(1.2); height:800px; z-index:5; visibility:hidden;"/>
<img src="IMAGE/w-cushion.png" style="position:absolute; margin-left:1450px; margin-top:270px; transform:rotate(2deg); visibility:hidden;"/>
<img src="IMAGE/w-light.png" style="position:absolute; margin-left:1310px; width:900px; margin-top:-130px; filter:brightness(0.95); visibility:hidden;" />
<img src="IMAGE/w-livingroom-table.png" style="position:absolute; margin-left:1310px; width:900px; margin-top:240px; filter:brightness(1.6); visibility:hidden;"/>
<img src="IMAGE/w-frame2.png" style="position:absolute; width:300px; margin-left:1500px; margin-top:120px; visibility:hidden;"/>
</div>

编辑:我添加了这段 javascript 代码并向每张图片添加了 id="myImageId' 但它只显示了一张图片

function showImage() {
var img = document.getElementById('myImageId');
img.style.visibility = 'visible';
}

最佳答案

var imagesRoot = document.getElementsByClassName("invisible-livingroom");
var images = imagesRoot[0].getElementsByTagName("img");
for (var i = 0; i < images.length; i++) {
images[i].style.visibility = "visible";
}

在 jQuery 中它就像

一样简单
$(".invisible-livingroom img").css("visibility", "hidden")

关于javascript - HTML 在点击时显示图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40825640/

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