这里分享下js判断当前选中哪个是tab页的方法。
设备:联想电脑
系统:win7
软件:Visual Studio 2017
1、首先来看一下要实现的效果,如下图所示,顶上是tab页卡,下面是内容。
2、然后准备页面的内容,如下图所示,tab运用ul布局,内容运用div布局。
3、接下来就是去除页面中的一些默认间距以及ul的list-style样式,如下图所示。
4、然后定义tab页卡以及内容的相关样式,如下图所示。
5、接着导入所需要的jquery的压缩库文件,如下图所示,版本大家自己选择。
6、最后就是实现选择一个页卡,然后展现页卡内内容的方法,JS实现tab页卡主要是运用了mouseenter的事件方法进行控制显示。
你要的是不是这个效果?如果是的话请向我要图片,没有图片效果可不好,呵呵~================================
<html>
<head>
<meta http-equiv="Content-Type" content="text/htmlcharset=gb2312">
<title>终端信息</title>
<script language="javascript">
//当前选中的页签
var CurrSelNo = 0
//页签的数目
var MaxTabs=6
function HovIt(objname)
{
if(CurrSelNo!=objname)
{
var btn1='tabInfotd'+objname
var btn2=btn1+'R'
document.getElementById(btn1).className = 'tabInfoHovT'
document.getElementById(btn2).className = "tabInfoHovTR"
}
}
function DefIt(objname)
{
if(CurrSelNo!=objname)
{
var btn1='tabInfotd'+objname
var btn2=btn1+'R'
document.getElementById(btn1).className = 'tabInfoDefT'
document.getElementById(btn2).className = "tabInfoDefTR"
}
}
function SelIt(objname)
{
var btn1
var btn2
for(i=0i<MaxTabsi++)
{
btn1='tabInfotd'+i
btn2=btn1+'R'
document.getElementById(btn1).className = 'tabInfoDefT'
document.getElementById(btn2).className = "tabInfoDefTR"
document.getElementById('tabInfo_frame'+i).style.display = 'none'
}
btn1='tabInfotd'+objname
btn2=btn1+'R'
document.getElementById(btn1).className = 'tabInfoSelT'
document.getElementById(btn2).className = "tabInfoSelTR"
document.getElementById('tabInfo_frame'+objname).style.display = ''
CurrSelNo = objname
}
</script>
</head>
<body>
<style type=text/css>
.tabInfoDisT{border-width:0px 0px 1px 0pxborder-color:#949878border-style:Solidheight:22pxfont-family:Microsoft Sans Seriffont-size:8ptcolor:Graypadding:2px 0 0 7pxcursor:Defaultbackground:url(images/ig_tab_winXP3.gif) no-repeat left 2px}
.tabInfoSelT{height:22pxfont-family:Microsoft Sans Seriffont-size:8ptcolor:Blackpadding:2px 0 2px 7pxcursor:Defaultbackground:url(images/ig_tab_winXP1.gif) no-repeat left top}
.tabInfoSelTR{width:6pxcursor:Defaultfont-size:2pxbackground:url(images/ig_tab_winXP1.gif) no-repeat right top}
.tabInfoDefT{border-width:0px 0px 1px 0pxborder-color:#949878border-style:Solidheight:22pxfont-family:Microsoft Sans Seriffont-size:8ptcolor:Blackpadding:2px 0 0 7pxcursor:Handbackground:url(images/ig_tab_winXP3.gif) no-repeat left 2px}
.tabInfoDefTR{border-width:0px 0px 1px 0pxborder-color:#949878border-style:Solidwidth:6pxcursor:Handfont-size:2pxbackground:url(images/ig_tab_winXP3.gif) no-repeat right 2px}
.tabInfoHovT{border-width:0px 0px 1px 0pxborder-color:#949878border-style:Solidheight:22pxfont-family:Microsoft Sans Seriffont-size:8ptcolor:Blackpadding:2px 0 0 7pxcursor:Handbackground:url(images/ig_tab_winXP2.gif) no-repeat left 2px}
.tabInfoHovTR{border-width:0px 0px 1px 0pxborder-color:#949878border-style:Solidwidth:6pxcursor:Handfont-size:2pxbackground:url(images/ig_tab_winXP2.gif) no-repeat right 2px}
</style>
<table border="0" cellspacing="0" cellpadding="0" id="igtabtabInfo" width="803px" height="316px" style="Z-INDEX:108">
<tr><td>
<table id="tabInfo_tbl" cellspacing="0" cellpadding="0" border="0" width="100%">
<tr valign="center">
<td>
<table cellspacing="0" cellpadding="0" border="0" height="100%" width="100%">
<tr>
<td nowrap id="tabInfotd0" align="center" class="tabInfoSelT" height="22px" unselectable="on" onmouseover="HovIt('0')" onmouseout="DefIt('0')" onclick="SelIt('0')">终端信息</td>
<td nowrap id="tabInfotd0R" class="tabInfoSelTR" width="6px" unselectable="on" onmouseover="HovIt('0')" onmouseout="DefIt('0')" onclick="SelIt('0')"></td>
</tr>
</table>
</td>
<td><table cellspacing="0" cellpadding="0" border="0" height="100%" width="100%"><tr>
<td nowrap id="tabInfotd1" align="center" class="tabInfoDefT" height="22px" unselectable="on" onmouseover="HovIt('1')" onmouseout="DefIt('1')" onclick="SelIt('1')">费用信息</td>
<td nowrap id="tabInfotd1R" class="tabInfoDefTR" width="6px" unselectable="on" onmouseover="HovIt('1')" onmouseout="DefIt('1')" onclick="SelIt('1')"></td>
</tr></table></td>
<td><table cellspacing="0" cellpadding="0" border="0" height="100%" width="100%"><tr>
<td nowrap id="tabInfotd2" align="center" class="tabInfoDefT" height="22px" unselectable="on" onmouseover="HovIt('2')" onmouseout="DefIt('2')" onclick="SelIt('2')">工单信息</td>
<td nowrap id="tabInfotd2R" class="tabInfoDefTR" width="6px" unselectable="on" onmouseover="HovIt('2')" onmouseout="DefIt('2')" onclick="SelIt('2')"></td>
</tr></table></td>
<td><table cellspacing="0" cellpadding="0" border="0" height="100%" width="100%"><tr>
<td nowrap id="tabInfotd3" align="center" class="tabInfoDefT" height="22px" unselectable="on" onmouseover="HovIt('3')" onmouseout="DefIt('3')" onclick="SelIt('3')">更改信息</td>
<td nowrap id="tabInfotd3R" class="tabInfoDefTR" width="6px" unselectable="on" onmouseover="HovIt('3')" onmouseout="DefIt('3')" onclick="SelIt('3')"></td>
</tr></table></td>
<td><table cellspacing="0" cellpadding="0" border="0" height="100%" width="100%"><tr>
<td nowrap id="tabInfotd4" align="center" class="tabInfoDefT" height="22px" unselectable="on" onmouseover="HovIt('4')" onmouseout="DefIt('4')" onclick="SelIt('4')">业务信息</td>
<td nowrap id="tabInfotd4R" class="tabInfoDefTR" width="6px" unselectable="on" onmouseover="HovIt('4')" onmouseout="DefIt('4')" onclick="SelIt('4')"></td>
</tr></table></td>
<!--复制此段,并将tabInfotd(X)和tabInfotd(X)R改为相应增加的数值,后面的HovIt,DefIt,SelIt函数的调用值也要修改 -->
<td><table cellspacing="0" cellpadding="0" border="0" height="100%" width="100%"><tr>
<td nowrap id="tabInfotd5" align="center" class="tabInfoDefT" height="22px" unselectable="on" onmouseover="HovIt('5')" onmouseout="DefIt('5')" onclick="SelIt('5')">投诉信息</td>
<td nowrap id="tabInfotd5R" class="tabInfoDefTR" width="6px" unselectable="on" onmouseover="HovIt('5')" onmouseout="DefIt('5')" onclick="SelIt('5')"></td>
</tr></table></td>
<!--段落结束-->
<td nowrap style="font-size:2pxcursor:defaultborder-width:0px 0px 1px 0pxborder-color:#949878border-style:Solidwidth:90%"></td>
</tr>
</table>
</td></tr>
<tr><td id="tabInfo_cp" bgcolor="#FEFCFD" style="border-width:0px 1px 1px 1pxborder-color:#949878border-style:Solidbackground-color:#FEFCFDpadding:3px 0px 0px 0pxheight:294pxwidth:803px">
<iframe id="tabInfo_frame0" src="http://www.szonline.net" style="" frameborder="0" width="801px" height="290px"></iframe>
<iframe id="tabInfo_frame1" src="http://www.sina.com.cn" style="display:none" frameborder="0" width="801px" height="290px"></iframe>
<iframe id="tabInfo_frame2" src="http://bbs.highot.net" style="display:none" frameborder="0" width="801px" height="290px"></iframe>
<iframe id="tabInfo_frame3" src="http://www.doyouhike.net" style="display:none" frameborder="0" width="801px" height="290px"></iframe>
<iframe id="tabInfo_frame4" src="http://www.szptt.net.cn" style="display:none" frameborder="0" width="801px" height="290px"></iframe>
<!--复制此段,并将tabInfo_frame改为相应增加的数值 -->
<iframe id="tabInfo_frame5" src="http://www.szptt.net.cn" style="display:none" frameborder="0" width="801px" height="290px"></iframe>
<!--段落结束-->
<div width="100%" height="100%" id="tabInfo_empty" style="display:none"></div>
</td></tr>
</table>
</body>
</html>