For IE, fireFox
在线演示:http://www.jxxg.com/dh20156/dhtabstrip/dhtabstrip.htm
dhtabstrip.js
function dhtabStrip(){
//author:dh20156;
this.width = 400;
this.height = 300;
this.tabwidth = 76;
this.fontSize = "12px";
this.background = "buttonface";
this.border = "2px outset";
var dhts = this;
var tabsplit = null;
var tabcontent = null;
var splitObj = [];
var length = 0;
var currenttab = 0;
var currentlist = [];
var showmore = false;
var lb = document.createElement("BUTTON");
lb.innerHTML = "<";
lb.style.width = "15px";
lb.style.height = "18px";
lb.style.fontSize = "12px";
lb.onclick = function(){viewpre();}
var rb = document.createElement("BUTTON");
rb.innerHTML = ">";
rb.style.width = "15px";
rb.style.height = "18px";
rb.style.fontSize = "12px";
rb.onclick = function(){viewnext();}
var mb = document.createElement("LI");
mb.style.styleFloat = "left";
mb.style.cssFloat = "left";
mb.style.position = "relative";
mb.style.left = "2px";
mb.style.padding = "0px";
mb.style.background = "none";
mb.style.border = "none";
mb.style.width = "32px";
mb.style.height = "20px";
mb.appendChild(lb);
mb.appendChild(rb);
this.showTab = function(index){
if(0<=index && length>0){
splitObj[currenttab].ts.style.top = "0px";
splitObj[currenttab].ts.style.left = "2px";
splitObj[currenttab].ts.style.zIndex = "0";
splitObj[currenttab].ts.style.paddingLeft = "5px";
if(index!=currenttab){
tabcontent.innerHTML = splitObj[index].tc;
}
splitObj[index].ts.style.paddingLeft = "7px";
splitObj[index].ts.style.top = "-1px";
splitObj[index].ts.style.left = "0px";
splitObj[index].ts.style.zIndex = "3";
currenttab = index;
}
}
function viewpre(){
var cl = parseInt(currentlist.length);
if(currentlist[0]!=0){
var tcl = currentlist;
currentlist = [];
for(var i=0;i<cl;i++){
var ni = parseInt(tcl[i])-1;
tabsplit.replaceChild(splitObj[ni].ts,tabsplit.childNodes[i]);
currentlist.push(ni);
}
rb.removeAttribute("disabled");
if(currentlist[0]==0){
lb.setAttribute("disabled","true");
}
}
}
function viewnext(){
var cl = parseInt(currentlist.length);
if(currentlist[cl-1]!=parseInt(length)-1){
var tcl = currentlist;
currentlist = [];
for(var i=cl-1;i>-1;i--){
var ni = parseInt(tcl[i])+1;
tabsplit.replaceChild(splitObj[ni].ts,tabsplit.childNodes[i]);
currentlist.push(ni);
}
currentlist.sort();
lb.removeAttribute("disabled");
if(currentlist[cl-1]==parseInt(length)-1){
rb.setAttribute("disabled","true");
}
}
}
this.init = function(targetObj){
var tabstrip = document.createElement("DIV");
tabstrip.style.width = this.width+26+"px";
tabstrip.style.height = this.height+26+"px";
tabstrip.style.fontSize = this.fontSize;
tabstrip.style.cursor = "default";
var ts = document.createElement("UL");
ts.style.margin = "0px";
ts.style.padding = "0px";
ts.style.width = this.width+"px";
ts.style.listStyle = "none";
var tc = document.createElement("UL");
tc.style.border = this.border;
tc.style.margin = "0px";
tc.style.padding = "10px";
tc.style.position = "relative";
var bp = parseInt(tc.style.borderTopWidth);
tc.style.top = -(bp+1)+"px";
tc.style.left = "0px";
tc.style.zIndex = "1";
tc.style.background = this.background;
tc.style.width = this.width+"px";
tc.height = this.height-20+"px";
tc.style.listStyle = "none";
tc.style.clear = "both";
var tcil = document.createElement("LI");
tcil.style.width = this.width+"px";
tcil.style.height = this.height-20+"px";
tcil.style.overflow = "auto";
tc.appendChild(tcil);
tabstrip.appendChild(ts);
tabstrip.appendChild(tc);
targetObj.appendChild(tabstrip);
tabsplit = ts;
tabcontent = tcil;
}
this.addTab = function(tab,content){
var tempint = length;
var tsil = document.createElement("LI");
tsil.setAttribute("index",length);
tsil.style.position = "relative";
tsil.style.top = "0px";
tsil.style.left = "2px";
tsil.style.styleFloat = "left";
tsil.style.cssFloat = "left";
tsil.style.zIndex = "0";
tsil.style.height = "20px";
tsil.style.lineHeight = "20px";
tsil.style.overflow = "hidden";
tsil.style.background = this.background;
tsil.style.padding = "0 5px";
tsil.style.borderLeft = this.border;
tsil.style.width = this.tabwidth+"px";
tsil.style.borderTop = this.border;
tsil.style.borderRight = this.border;
tsil.title = tab;
tsil.innerHTML = tab;
tsil.onclick = function(){dhts.showTab(this.getAttribute("index"));}
if(0 == length){
tsil.style.padding = "0 5px 0 7px";
tsil.style.top = "-1px";
tsil.style.left = "0px";
tsil.style.zIndex = "3";
tabcontent.innerHTML = content;
}
splitObj[length] = {"ts":tsil,"tc":content};
length += 1;
if(length*(this.tabwidth+14)<this.width){
tabsplit.appendChild(tsil);
currentlist.push(length-1);
}else{
if(!showmore){
lb.setAttribute("disabled","true");
tabsplit.appendChild(mb);
showmore = true;
}else{
rb.removeAttribute("disabled");
}
}
}
this.removeTab = function(index){
if(0<=index && index<length){
var rindex = splitObj[index].ts.getAttribute("index");
splitObj.splice(index,1);
var atb = null;
currentlist.sort();
for(var i=0;i<currentlist.length;i++){
if(rindex==currentlist[i]){
atb = i;
}
}
if(showmore){
for(var s=0;s<splitObj.length;s++){
splitObj[s].ts.setAttribute("index",s);
}
if(atb!=null){
if(0==index){
for(var n=currentlist.length-1;n>atb-1;n--){
var ni = parseInt(currentlist[n]);
tabsplit.replaceChild(splitObj[ni].ts,tabsplit.childNodes[n]);
currentlist[n] = ni;
}
currentlist.sort();
}else if (index==length-1){
for(var n=0;n<currentlist.length;n++){
var ni = parseInt(currentlist[n])-1;
tabsplit.replaceChild(splitObj[ni].ts,tabsplit.childNodes[n]);
currentlist[n] = ni;
}
}else{
if(currentlist[0]>0){
for(var n=0;n<currentlist.length;n++){
var ni = parseInt(currentlist[n])-1;
if(n<atb+1){
tabsplit.replaceChild(splitObj[ni].ts,tabsplit.childNodes[n]);
}
currentlist[n] = ni;
}
}else{
for(var n=currentlist.length-1;n>atb-1;n--){
var ni = parseInt(currentlist[n]);
tabsplit.replaceChild(splitObj[ni].ts,tabsplit.childNodes[n]);
currentlist[n] = ni;
}
currentlist.sort();
}
}
}else{
for(var p=0;p<currentlist.length;p++){
currentlist[p] = p;
}
}
}else{
if(atb!=null){
tabsplit.removeChild(tabsplit.childNodes[atb]);
currentlist.splice(atb,1);
for(var b=0;b<currentlist.length;b++){
currentlist[b] = b;
splitObj[b].ts.setAttribute("index",b);
}
}
}
//alert("current:"+currenttab+"- index:"+index);
if(0==splitObj.length){
currenttab = 0;
}else{
if(currenttab==index){
if(currenttab<length-1){
currenttab = index;
}else{
currenttab -= 1;
}
}else{
if(currenttab>0 && currenttab>index){
currenttab -= 1;
}
}
}
if(length>1){
tabcontent.innerHTML = splitObj[currenttab].tc;
splitObj[currenttab].ts.style.paddingLeft = "7px";
splitObj[currenttab].ts.style.top = "-1px";
splitObj[currenttab].ts.style.left = "0px";
splitObj[currenttab].ts.style.zIndex = "3";
}else{
tabcontent.innerHTML = "";
}
if(showmore){
if((length-1)*(this.tabwidth+14)<=this.width){
tabsplit.removeChild(tabsplit.childNodes[tabsplit.childNodes.length-1]);
rb.removeAttribute("disabled");
showmore = false;
}
}
length -= 1;
}
}
this.getChildNodes = function(){
return splitObj;
}
}
调用 dhtabstrip.htm
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=gb2312">
<title>dhTabStrip 1.0</title>
<script language="javascript" type="text/javascript" src="dhtabstrip.js"></script>
</head>
<body>
<div id="daa" style="display:none;">
<fieldset>
<legend>主页</legend>
可以更改主页。<br/>
地址:<input type="text" style="width:300px;"><br/>
<input type="button" value="使用当前页(C)" style="width:120px;">
<input type="button" value="使用默认页(D)" style="width:120px;">
<input type="button" value="使用空白页(B)" style="width:120px;">
</fieldset>
</div>
<div id="dab" style="display:none;">
<fieldset>
<legend>该区域的安全级别</legend>
移动滑块设置该区域的安全级别。<br/>
<b>安全级 - 中</b><br/>
<input type="button" value="自定义级别(C)..." style="width:120px;">
<input type="button" value="默认级别(D)" style="width:120px;" disabled>
</fieldset>
</div>
<div id="dac" style="display:none;">
<fieldset>
<legend>设置</legend>
要使用滑块设置隐私等级而不使用自定义设置,请单击“默认”按钮。<br/>
<b>自定义</b><br/>
- 高级或导入的设置<br/>
<input type="button" value="导入(I)..." style="width:100px;">
<input type="button" value="高级(V)..." style="width:100px;">
<input type="button" value="默认(D)" style="width:100px;">
</fieldset>
</div>
<div id="dad" style="display:none;">
<fieldset>
<legend>分级审查</legend>
分级系统可帮助您控制在该计算机上看到的 Internet 内容。<br/>
<input type="button" value="启用(E)..." style="width:100px;">
<input type="button" value="设置(T)..." style="width:100px;" disabled>
</fieldset>
</div>
第一个TabStrip<br/>
getChildNodes()方法获得dhTabStrip节点对象<select id="showelement" style="width:200px;" οnchange="dt.showTab(this.value);alert(this.options[this.selectedIndex].getAttribute('ntext'));"></select>可以选择不同的选项进行切换!<br/>
<input type="button" value="remove1" οnclick="dt.removeTab(0);"><input type="button" value="remove2" οnclick="dt.removeTab(1);"><input type="button" value="remove3" οnclick="dt.removeTab(2);"><input type="button" value="remove4" οnclick="dt.removeTab(3);"><input type="button" value="remove5" οnclick="dt.removeTab(4);"><br/>
<input type="button" value="给第一个TabStrip添加一个新的标签" οnclick="dt.addTab('newTab','this is newTab');"><br/><br/>
<script language="javascript" type="text/javascript">
var dt = new dhtabStrip();
dt.border = "2px outset";
dt.init(document.body);
dt.addTab("常规",document.getElementById("daa").innerHTML);
dt.addTab("安全",document.getElementById("dab").innerHTML);
dt.addTab("隐私",document.getElementById("dac").innerHTML);
dt.addTab("内容",document.getElementById("dad").innerHTML);
</script>
第二个TabStrip
<script language="javascript" type="text/javascript">
var dt2 = new dhtabStrip();
dt2.tabwidth = 70;
dt2.width = 200;
dt2.height = 150;
dt2.border = "1px solid #808080";
dt2.init(document.body);
dt2.addTab("常规常规常规常规","常规要设置一个 Internet 连接,单击“设置”。");
dt2.addTab("安全安全安全安全","安全检查 Internet Explorer 是否为默认的浏览器(<u>I</u>)");
dt2.addTab("隐私隐私隐私隐私","隐私还原默认设置(<u>R</u>)");
dt2.addTab("内容内容内容内容","内容要设置一个 Internet 连接,单击“设置”。");
dt2.addTab("连接连接连接连接","连接要设置一个 Internet 连接,单击“设置”。");
dt2.addTab("程序程序程序程序","程序检查 Internet Explorer 是否为默认的浏览器(<u>I</u>)");
dt2.addTab("高级高级高级高级","高级还原默认设置(<u>R</u>)");
</script>
<script language="javascript" type="text/javascript">
function getdtelement(){
var str = "";
var o = dt.getChildNodes();
for(var i=0;i<o.length;i++){
var oOption = document.createElement("OPTION");
oOption.innerHTML = i+1+" "+o[i].ts.innerHTML;
oOption.value = i;
oOption.setAttribute("ntext",o[i].tc);
document.getElementById("showelement").appendChild(oOption);
}
}
getdtelement();
</script>
</body>
</html>