本文实例讲述了射流研究…实现简单的可切换选项卡效果的方法。分享给大家供大家参考。具体如下:
如图,最简单的纯粹的选项卡
第一步,当然是先写超文本标记语言代码和钢性铸铁样式
!DOCTYPE html html html healtheeta charset=' GB 2312 '/title无标题文档/titlestylebody,ul,li { margin:0划水:0;font :12 px/1.5 arial;}ul、李{列表式:无;}.包装{ width :500 pxmargin :20 px汽车;}.隐藏{ display : none } # tab _ t { height :25 pxborder-bottom :1 px实心# ccc} # tab _ t li { float:left宽度:80 px高度:24px线高:24 pxmargin:0 4px文本对齐:居中;border:1px固体# cccborder-底部:无;background : # F5 F5 F5 cursor :指针} # tab _ t . act { position : relative;高度:25px保证金-底部:-1px;背景# fff} # tab _ c {边框:1 px实心# CCC边框-top :无;padd :20 px }/style/head dydiv class=' wrap ' ul id=' tab _ t ' Li class=' act '选择1/李莉选择2/李莉选择3/李莉选择4/li /ul div id='tab_c' div内容1/div div class='隐藏'内容2/div类=隐藏内容3/div类=隐藏内容4/分区/分区/分区/正文/html第二步,实现简单的切换效果
要点1:
ABC。文件。getelementsbytagname(' Li ')取得字母表下面的所有标签为里的元素,返回的是一个元素集合,有数组的一些属性。
要点2:循环,先循环给里加上onclick事件,再在线事件点击的时候,再循环让所有选项卡的行动样式去掉,所有的内容隐藏。然后让所点击的选项及对应内容显示。要点3:
tab_t_li[i].索引=我;在循环时,给选项卡加一个额外的属性并赋值,以做选项卡和内容的对应。
!DOCTYPE html html html healtheeta charset=' GB 2312 '/title无标题文档/titlestylebody,ul,li { margin:0划水:0;font :12 px/1.5 arial;}ul、李{列表式:无;}.包装{ width :500 pxmargin :20 px汽车;}.隐藏{ display : none } # tab _ t { height :25 pxborder-bottom :1 px实心# ccc} # tab _ t li { float:left宽度:80 px高度:24px线高:24 pxmargin:0 4px文本对齐:居中;border:1px固体# cccborder-底部:无;background : # F5 F5 F5 cursor :指针} # tab _ t . act { position : relative;高度:25px保证金-底部:-1px;背景# fff} # tab _ c {边框:1 px实心# CCC边框-top :无;padd :20 px }/样式脚本窗口。onload=function(){ var tab _ t=document。getelementbyid(' tab _ t ');var tab _ t _ Li=tab _ t . getelementsbytagname(' Li ');var tab _ c=文档。getelementbyid(' tab _ c ');var tab _ c _ Li=tab _ c . getelementsbytagname(' div ');var len=tab _ t _ Li . length var I=0;for(I=0;伊琳;i ){ tab_t_li[i].索引=我;tab_t_li[i].onclick=function(){ for(I=0;伊琳;i ){ tab_t_li[i].类名=tab_c_li[i].隐藏tab_t_li[this.index].acttab_c_li[this.index].{ } }/script/head dydiv=' wrap ' ul id=' tab _ t ' Li class=' act '选择1/李莉选择2/李莉选择3/李莉选择4/li /ul div id='tab_c' div内容1/div div class='隐藏'内容2/div类=隐藏内容3/div类=隐藏内容4/分区/分区/分区/正文/html第三步,写成函数。上面的写法只能一个页面用一个选项卡,如果再加一个的话,就需要复制一份,再改很多变量名。
要点:tab_t_li[i][evt]因为传值的时候是字符串,如果直接写的话就是tab_t_li[i].' onclick '这样话是执行不了的,tab_t_li['onclick']这样执行没问题。
好了,现在一个页面上就可以有多个切换了,只需要调用函数的时候,写上相应的编号名和标签名,事件名称就可以了
!DOCTYPE html html html healtheeta charset=' GB 2312 '/title无标题文档/titlestylebody,ul,li { margin:0划水:0;font :12 px/1.5 arial;}ul、李{列表式:无;}.包装{ width :500 pxmargin :20 px汽车;}.隐藏{ display : none } # tab _ t { height :25 pxborder-bottom :1 px实心# ccc} # tab _ t li { float:left宽度:80 px高度:24px线高:24 pxmargin:0 4px文本对齐:居中;border:1px固体# cccborder-底部:无;background : # F5 F5 F5 cursor :指针} # tab _ t . act { position : relative;高度:25px保证金-底部:-1px;背景# fff} # tab _ c {边框:1 px实心# CCC边框-top :无;padd :20 px }/style script window。onload=function(){ tab(' tab _ t ',' li ',' tab_c ',' div ',' onmouseover') function tab(tab_t,tab_t_tag,tab_c,tag_c_tag,evt){ var tab _ t=document。getelementbyid(tab _ t);var tab _ t _ Li=tab _ t . getelementsbytagname(tab _ t _ tag);var tab _ c=文档。getelementbyid(tab _ c);var tab _ c _ Li=tab _ c . getelementsbytagname(tag _ c _ tag);var len=tab _ t _ Li . length var I=0;for(I=0;伊琳;i ){ tab_t_li[i].索引=我;tab _ t _ Li[I][evt]=function(){ for(I=0;伊琳;i ){ tab_t_li[i].类名=tab_c_li[i].隐藏tab_t_li[this.index].acttab_c_li[this.index].} } } }/script/head dydiv=' wrap ' ul id=' tab _ t ' Li class=' act '选择1/李莉选择2/李莉选择3/李莉选择4/li /ul div id='tab_c' div内容1/div div class='隐藏'内容2/div类=隐藏内容3/div类=隐藏内容4/分区/分区/分区/正文/html希望本文所述对大家的爪哇岛描述语言程序设计有所帮助。