gpt4 book ai didi

javascript - 如何用JS显示一个元素并隐藏所有其他元素

转载 作者:行者123 更新时间:2023-12-03 05:48:01 24 4
gpt4 key购买 nike

当一个人点击一个按钮时,使用 ng-click 指令,我调用一个函数 openAbout(),我希望显示一个 div 并隐藏所有其他 div。它适用于这段代码,但是有什么可以只制作两个语句,而不是五个语句吗?例如,我想要首先显示,然后隐藏所有其他内容。谢谢

<md-button id="about" ng-click="openAbout()">
About Us
</md-button>


$scope.openAbout=function() {
document.getElementById("first").style.display = "block";
document.getElementById("second").style.display = "none";
document.getElementById("third").style.display = "none";
document.getElementById("fourth").style.display = "none";
document.getElementById("fifth").style.display = "none";
};

最佳答案

你的意思是

$scope.openAbout=function(){
$(".divClass").hide(); // give all divs the same class
$("#first").show();
};

除非你想使用 ngShow/ngHide: https://scotch.io/tutorials/how-to-use-ngshow-and-nghide

关于javascript - 如何用JS显示一个元素并隐藏所有其他元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40257135/

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