Home >Web Front-end >JS Tutorial >How to implement button in js to change the display of text content in a certain div (code example)
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('button'); var div = document.getElementsByClassName('content'); 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=''; div[j].style.display='none'; } this.className='active'; div[n].style.display='block'; div[n].p } }(i)) } </script>
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!