首页 > 代码库 > tab切换(onmouseover/onclick)

tab切换(onmouseover/onclick)

<style>

 

</style>

<div id="tab_bar">
  <ul>


    <li id="tab1" style="background-color: white; color:red;" onm ouseover="myclick(1)">实时资讯</li>
    <li id="tab2" onm ouseover="myclick(2)">外汇资讯</li>
    <li id="tab3" onm ouseover="myclick(3)">专家策略</li>
  </ul>
</div>

<div class="tab_css" id="tab1_content"></div>

<div class="tab_css" id="tab2_content"></div>

<div class="tab_css" id="tab3_content"></div>

 

 

<script>

var myclick = function(v) {

var div=document.getElementById(‘tab_bar‘);
var llis=div.children[0].children;
for(var i = 0; i < llis.length; i++) {
var lli = llis[i];
if(lli == document.getElementById("tab" + v)) {
lli.style.backgroundColor = "white";
lli.style.color = "red";
// lli.style.borderbottom = "none";
} else {
lli.style.backgroundColor = "#efefef";
lli.style.color = "#353535";
}
}

var divs = document.getElementsByClassName("tab_css");
for(var i = 0; i < divs.length; i++) {

var divv = divs[i];

if(divv == document.getElementById("tab" + v + "_content")) {
divv.style.display = "block";
} else {
divv.style.display = "none";
}
}

};

</script>

tab切换(onmouseover/onclick)