效果图:
代码如下:
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>原生js选项卡写法</title> <style> #p1 p{width: 200px;height: 200px;border: 1px solid #FF0000;display: none;} .active{background: red;} </style> <script> window.onload=function(){//原生js选项卡写法 var op = document.getElementById('p1'); var aInput = document.getElementsByTagName('input'); var aCon = op.getElementsByTagName('p'); for(var i=0;i<aInput.length;i++){ aInput[i].index = i; aInput[i].onclick = function(){ for(var i=0;i<aInput.length;i++){ aInput[i].className = ''; aCon[i].style.display = 'none'; } this.className= 'active'; aCon[this.index].style.display = 'block'; } } } </script> </head> <body> <p id="p1"> <input class="active" type="button" value="1" /> <input type="button" value="2"/> <input type="button" value="3"/> <p style="display: block;">11111111111</p> <p>22222222222</p> <p>333333333333</p> </p> </body> </html>更多相关内容:
-
无相关信息