点击显示更多 - 也许JS? [英] Click to show more - maybe JS?

查看:109
本文介绍了点击显示更多 - 也许JS?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不确定使用何种语言或如何执行此操作,但我希望在页面上有一个单词,并且在单击时,它将显示更多内容。如果再次点击它,那些东西会再次隐藏起来?有什么想法?

I am not sure what language or how to do this, but I am looking to have a word on a page, and when clicked, it will reveal more underneath. If it is clicked again, that stuff will hide away again? Any ideas?

推荐答案

基本上,你需要操纵显示要隐藏/显示的元素的CSS属性:

Basically, you will need to manipulate the display CSS property of the element to be hidden/revealed:

<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>

这篇关于点击显示更多 - 也许JS?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆