Home > Web Front-end > JS Tutorial > body text

How to implement button in js to change the display of text content in a certain div (code example)

青灯夜游
Release: 2018-10-24 15:49:54
forward
3270 people have browsed it

The content of this article is to introduce how to implement button in js to change the display of text content in a certain div. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.

nbsp;html>


    <meta>
    <title></title>
<style>
*{ padding:0px;
    margin:0px;}
.wrapper div{display:none;
    width:200px;
    height:250px;
    border:10px solid #FF3;
    }
div.start{text-align:center;
    display:block;
    width:200px;
    border:5px solid #F00;
    }
.active{
    background-color:orange;}        
    </style>



<div>辣鸡游戏</div>
<div>
<button>第一关</button>
<button>第二关</button>
<button>第三关</button>
<button>第四关</button>
<div>你就是个大傻逼</div>
<div>辣鸡</div>
<div>废物</div>
<div>蠢狗</div>
</div>
<script>
var btn = document.getElementsByTagName(&#39;button&#39;);
var div = document.getElementsByClassName(&#39;content&#39;);
for(var i =0; i<btn.length; i++){
    (function(n){
    btn[n].onclick = function(){
        for(var j = 0; j < btn.length; j++){
            btn[j].className=&#39;&#39;;
            div[j].style.display=&#39;none&#39;;
            }
        this.className=&#39;active&#39;;
        div[n].style.display=&#39;block&#39;;
        div[n].p
        
        }
    }(i))
}

</script>

Copy after login

How to implement button in js to change the display of text content in a certain div (code example)

How to implement button in js to change the display of text content in a certain div (code example)

The above is the detailed content of How to implement button in js to change the display of text content in a certain div (code example). For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:cnblogs.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template