gpt4 book ai didi

javascript - 我是否正确编写了这些 HTML img 标签?

转载 作者:行者123 更新时间:2023-11-28 16:27:02 30 4
gpt4 key购买 nike

我在这里想要做的是使用 z-index 属性将这些图像堆叠在另一个图像之上,并使用按钮更改 z-index 以使其他图像显示在顶部。我试图通过将图像全部设置在同一个位置然后使用 javascript 函数根据按钮更改图像的 z-index 属性来做到这一点。这不是一种非常漂亮的方法,但除了使用 visibility 属性之外我想不出其他方法。谁能帮助我实现我对这应该如何运作的看法。无法从这里真正弄清楚。

     <!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
</head>
<body>

<center><img src="/tools/c_clamps.jpg" id="tool1" height="248" width="364" style = "position:absolute; z-index:1";></center>
<center><img src="/tools/crescent_wrench.jpg" id="tool2" height="248" width="364" style = "position:absolute; z-index:0";></center>
<center><img src="/tools/chisels.jpg" id="tool3" height="248" width="364" style = " position:absolute; z-index:-1";></center>


<script language="javascript" type="text/javascript">
<!--
//<![CDATA[
function select(picture){
if(picture == 1)
{
document.getElementByID("tool1").z-index:1;
document.getElementByID("tool2").z-index:0;
document.getElementByID("tool3").z-index:-1;
}
else if(picture == 2)
{
document.getElementByID("tool1").z-index:0;
document.getElementByID("tool2").z-index:1;
document.getElementByID("tool3").z-index:-1;
}
else if(picture == 3)
{
document.getElementByID("tool1").z-index:-1;
document.getElementByID("tool2").z-index:0;
document.getElementByID("tool3").z-index:1;
}
}
//]]>
//-->
</script>
<br/>
<div width="400" style="display: block;margin-left: auto;margin-right: auto;text-align: center">
<button type = "button" onclick="select(1);">Clamps</button>
<button type = "button" onclick="select(2);">Chisels</button>
<button type = "button" onclick="select(3);">C. Wrench</button>
</div>


</body>
</html>

最佳答案

我认为语法应该是:

 document.getElementById("tool1").style.zIndex = 0;

关于javascript - 我是否正确编写了这些 HTML img 标签?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42847702/

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