我不知道用什么语言或如何做到这一点,但我希望在页面上有一个单词,当点击它时,它会在下面显示更多内容.如果再次点击它,那些东西会再次隐藏起来?有任何想法吗?
基本上,您需要操纵display
要隐藏/显示的元素的CSS属性:
<span id="showHide">Show</span>
<div id="foo" style="display:none">Here is some text</div>
<script>
document.getElementById("showHide").onclick = function() {
var theDiv = document.getElementById("foo");
if(theDiv.style.display == 'none') {
theDiv.style.display = 'block';
this.innerHTML = 'Hide';
} else {
theDiv.style.display = 'none';
this.innerHTML = 'Show';
}
}
</script>
Run Code Online (Sandbox Code Playgroud)