javascript - 用javascript隐藏部分不起作用
问题描述
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>
推荐阅读
- typescript - 使用哪个运算符返回内部可观察对象?
- webpack - Webpack 4,this.htmlWebpackPlugin.getHooks 不是函数
- c# - RestSharp - 如何返回热门任务?
- reactjs - 在 React 中编辑/修改对象数组
- javascript - 如何在动态对象内的数组中添加/删除
- python - 在每个循环中添加任意数量的列
- r - 堆叠的 geom_area 在层之间产生空白
- javascript - 如何使用 Spotify API 设置音量?
- python - 带有 numpy 的列名
- java - 如何从另一个线程中访问和修改操作栏内容