切換tab,而且動態添加標籤
<script type="text/javascript"> /*處理ie七、ie8不兼容getElementsByClassName*/ if(!document.getElementsByClassName) { document.getElementsByClassName = function(className, element) { var children = (element || document).getElementsByTagName('*'); var elements = new Array(); for (var i=0;i<children.length;i++) { var child = children[i]; var classNames = child.className.split(' '); for (var j=0;j<classNames.length;j++) { if (classNames[j] == className) { elements.push(child); break; } } } return elements; }; } var newNode = document.createElement("i"); var _titles = document.getElementsByClassName('title'); var _items = document.getElementsByClassName('_items'); var _as = document.getElementsByClassName('title_a'); _items[0].style.display = 'block'; _titles[0].insertBefore(newNode, _as[0]); for(var i = 0; i <_titles.length; i++){ _titles[i].index = i; _titles[i].onclick = function (){ for(var j = 0;j< _items.length;j++){ _items[j].style.display = 'none'; } _items[this.index].style.display = 'block'; _titles[this.index].insertBefore(newNode, _as[this.index]); } } </script>
歡迎關注本站公眾號,獲取更多信息