Home  >  Article  >  Web Front-end  >  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)

青灯夜游
青灯夜游forward
2018-10-24 15:49:543283browse

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>

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!

Statement:
This article is reproduced at:cnblogs.com. If there is any infringement, please contact admin@php.cn delete