javascript - 使用 javascript 隐藏部分不起作用

标签 javascript html css

function showX()

document.getElementById("one").style.display = "block"; 
document.getElementById("two").style.display = "none"; 
document.getElementById("three").style.display = "none"; 

function showZ()

document.getElementById("one").style.display = "none"; 
document.getElementById("two").style.display = "block"; 
document.getElementById("three").style.display = "none"; 

function showY()

document.getElementById("one").style.display = "none"; 
document.getElementById("two").style.display = "none"; 
document.getElementById("three").style.display = "block"; 
div {display:inline;}
div img {width:400px;height: 400px;}

#one {
display: none;
}

#two {
display: none;
}

#three {
display: none;
}
<html>

<section id="one">
take this info es cool 1 
</section>

<section id="two">
take this info es cool 2 
</section>

<section id="three">
take this info es cool 3
</section>

</html>

当我点击我的图片时没有任何反应? 谁能帮帮我,好吗?

我已经尝试解决这个问题一段时间了,所以决定来这里。 在此先感谢您的帮助!

我是编程新手,我正在创建的网站元素需要这个。

我需要它,所以当我访问该网站时,它只会显示图片而不显示部分。单击图片时,它将显示第一部分,但隐藏其他部分。

最佳答案

您缺少大括号 {}。这是工作。您还应该调用该函数。

function showX(){

document.getElementById("one").style.display = "block"; 
document.getElementById("two").style.display = "none"; 
document.getElementById("three").style.display = "none"; 

}

function showZ(){

document.getElementById("one").style.display = "none"; 
document.getElementById("two").style.display = "block"; 
document.getElementById("three").style.display = "none"; 

}

function showY(){

document.getElementById("one").style.display = "none"; 
document.getElementById("two").style.display = "none"; 
document.getElementById("three").style.display = "block";

}

showZ();
div {display:inline;}
div img {width:400px;height: 400px;}

#one {
display: none;
}

#two {
display: none;
}

#three {
display: none;
}
<html>

<section id="one">
take this info es cool 1 
</section>

<section id="two">
take this info es cool 2 
</section>

<section id="three">
take this info es cool 3
</section>

</html>

关于javascript - 使用 javascript 隐藏部分不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54816474/

相关文章:

javascript - 如何将当前类添加到单击的元素并在单击另一个元素时将其删除?

javascript - jQuery 隐藏标题中没有 $somestuff 的图像

jquery - IE8 - 没有链接的 jQuery slider 下一个/上一个按钮

javascript - 如何使用 jquery .show() 在同一个父元素中应用一个函数?

php - 当用户点击提交按钮时,index.php 不会捕获该操作并更新数据库

javascript - 获取很多复选框的值,然后通过foreach循环打印出来

php - 使用来自同一网站上其他页面的超链接定位特定选项卡

javascript - 带有嵌套表的数据表没有功能

javascript - bootstrap 3 datetimepicker开始日期提前2周

javascript - 处理多个 .search() 参数的结果