<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Tab选项卡和滑动门同时布局在一个页面上丨芯晴网页特效丨CsrCode.Cn</title>
<meta http-equiv="content-type" content="text/xml;charset=utf-8" />
<style type="text/css">
*{margin:0;padding:0;font-size:13px;line-height:1.5;}
body{padding:20px;}
.cur{color:#f60;border-bottom:1px solid #fff;font-weight:bold;background:#fff;cursor:default;}
#tab_,dl{position:relative;float:left;height:100px;width:300px;}
h4,dt{float:left;height:20px;margin:0 0 0 8px;display:inline;line-height:20px;width:60px;border:1px solid #ccc;position:relative;z-index:11;text-align:center;font-weight:normal;cursor:pointer;background:#eee;}
.c,dd{position:absolute;top:21px;border:1px solid #ccc;left:0;width:250px;padding:20px;overflow:hidden;display:block;}
#tab_{clear:left;}
h1{clear:left;padding:10px 0}
#tab_1.cur{color:#f60}
#tab_2.cur{color:blue}
#tab_3.cur{color:green}
</style>
</head>
<body>
<h1>mouseover</h1>
<dl id="tab">
<dt>美国</dt>
<dd>我都不怕</dd>
<dt>朝鲜</dt>
<dd>谁都怕我</dd>
<dt>某国</dt>
<dd>我谁都怕</dd>
</dl>
<h1>mouseover</h1>
<dl id="tab">
<dt>美国</dt>
<dd>我都不怕</dd>
<dt>朝鲜</dt>
<dd>谁都怕我</dd>
<dt>某国</dt>
<dd>我谁都怕</dd>
</dl>
<h1>click</h1>
<div id="tab_">
<h4>orange</h4>
<div class="c">桔红</div>
<h4>blue</h4>
<div class="c">蓝色</div>
<h4>green</h4>
<div class="c">绿色</div>
</div>
<script type="text/javascript">
function id(elem) {return document.getElementById(elem)}
function show(elem) {elem.style.display = "";}
function hide(elem) {elem.style.display = "none";}
function next( elem ) {
do {
elem = elem.nextSibling;
} while ( elem && elem.nodeType != 1 );
return elem;
}
function tab(a, p) {
var p = (p === undefined) ? {e:"onclick",n:1} : p,
node = id(a).firstChild,
x = [];
p.e = (p.e === undefined) ? "onclick" : p.e;
p.n = (p.n === undefined) ? 1 : p.n;
node=(node.nodeType !== 1)?next(node):node;
for (var i = 1, node; node; i++, node = next(node)) {
x[i] = node;
}
for (var i = 1; x[i]; i++) {
if(i % 2 == 0){hide(x[i]);x[i-1].id=a+(i/2)}
x[p.n*2-1].className = "cur";
show(x[p.n*2]);
temp = function (i) {
if (i % 2 == 1) {
x[i][p.e] = function () {
for (var j = 1; x[j]; j++) {
if (j % 2 == 0) {
hide(x[j]);
x[j-1].className = ""
}
}
show(x[i+1]);
x[i].className = "cur"
}
} else {
return null
}
}(i)
}
}
tab("tab",{e:"onmouseover",n:2});
tab("tab_")
</script>
</body>
</html>第一个mouseover有效果,但是第二个就没有。我怀疑可能是ID应该改为CLASS,但是我不懂JS。谁能看看这个怎么改啊...跪谢了。。
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Tab选项卡和滑动门同时布局在一个页面上丨芯晴网页特效丨CsrCode.Cn</title>
<meta http-equiv="content-type" content="text/xml;charset=utf-8" />
<style type="text/css">
*{margin:0;padding:0;font-size:13px;line-height:1.5;}
body{padding:20px;}
.cur{color:#f60;border-bottom:1px solid #fff;font-weight:bold;background:#fff;cursor:default;}
#tab_,dl{position:relative;float:left;height:100px;width:300px;}
h4,dt{float:left;height:20px;margin:0 0 0 8px;display:inline;line-height:20px;width:60px;border:1px solid #ccc;position:relative;z-index:11;text-align:center;font-weight:normal;cursor:pointer;background:#eee;}
.c,dd{position:absolute;top:21px;border:1px solid #ccc;left:0;width:250px;padding:20px;overflow:hidden;display:block;}
#tab_{clear:left;}
h1{clear:left;padding:10px 0}
#tab_1.cur{color:#f60}
#tab_2.cur{color:blue}
#tab_3.cur{color:green}
</style>
</head>
<body>
<h1>mouseover</h1>
<dl id="tab">
<dt>美国</dt>
<dd>我都不怕</dd>
<dt>朝鲜</dt>
<dd>谁都怕我</dd>
<dt>某国</dt>
<dd>我谁都怕</dd>
</dl>
<h1>mouseover</h1>
<dl id="tab">
<dt>美国</dt>
<dd>我都不怕</dd>
<dt>朝鲜</dt>
<dd>谁都怕我</dd>
<dt>某国</dt>
<dd>我谁都怕</dd>
</dl>
<h1>click</h1>
<div id="tab_">
<h4>orange</h4>
<div class="c">桔红</div>
<h4>blue</h4>
<div class="c">蓝色</div>
<h4>green</h4>
<div class="c">绿色</div>
</div>
<script type="text/javascript">
function id(elem) {return document.getElementById(elem)}
function show(elem) {elem.style.display = "";}
function hide(elem) {elem.style.display = "none";}
function next( elem ) {
do {
elem = elem.nextSibling;
} while ( elem && elem.nodeType != 1 );
return elem;
}
function tab(a, p) {
var p = (p === undefined) ? {e:"onclick",n:1} : p,
node = id(a).firstChild,
x = [];
p.e = (p.e === undefined) ? "onclick" : p.e;
p.n = (p.n === undefined) ? 1 : p.n;
node=(node.nodeType !== 1)?next(node):node;
for (var i = 1, node; node; i++, node = next(node)) {
x[i] = node;
}
for (var i = 1; x[i]; i++) {
if(i % 2 == 0){hide(x[i]);x[i-1].id=a+(i/2)}
x[p.n*2-1].className = "cur";
show(x[p.n*2]);
temp = function (i) {
if (i % 2 == 1) {
x[i][p.e] = function () {
for (var j = 1; x[j]; j++) {
if (j % 2 == 0) {
hide(x[j]);
x[j-1].className = ""
}
}
show(x[i+1]);
x[i].className = "cur"
}
} else {
return null
}
}(i)
}
}
tab("tab",{e:"onmouseover",n:2});
tab("tab_")
</script>
</body>
</html>第一个mouseover有效果,但是第二个就没有。我怀疑可能是ID应该改为CLASS,但是我不懂JS。谁能看看这个怎么改啊...跪谢了。。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Tab选项卡和滑动门同时布局在一个页面上丨芯晴网页特效丨CsrCode.Cn</title>
<meta http-equiv="content-type" content="text/xml;charset=gbk" />
<style type="text/css">
*{margin:0;padding:0;font-size:13px;line-height:1.5;}
body{padding:20px;}
.cur{color:#f60;border-bottom:1px solid #fff;font-weight:bold;background:#fff;cursor:default;}
#tab_,dl{position:relative;float:left;height:100px;width:300px;}
h4,dt{float:left;height:20px;margin:0 0 0 8px;display:inline;line-height:20px;width:60px;border:1px solid #ccc;position:relative;z-index:11;text-align:center;font-weight:normal;cursor:pointer;background:#eee;}
.c,dd{position:absolute;top:21px;border:1px solid #ccc;left:0;width:250px;padding:20px;overflow:hidden;display:block;}
#tab_{clear:left;}
h1{clear:left;padding:10px 0}
#tab_1.cur{color:#f60}
#tab_2.cur{color:blue}
#tab_3.cur{color:green}
</style>
</head>
<body>
<h1>mouseover</h1>
<dl id="tab">
<dt>美国</dt>
<dd>我都不怕</dd>
<dt>朝鲜</dt>
<dd>谁都怕我</dd>
<dt>某国</dt>
<dd>我谁都怕</dd>
</dl>
<h1>mouseover</h1>
<dl id="tab2">
<dt>美国</dt>
<dd>我都不怕</dd>
<dt>朝鲜</dt>
<dd>谁都怕我</dd>
<dt>某国</dt>
<dd>我谁都怕</dd>
</dl>
<h1>click</h1>
<div id="tab_">
<h4>orange</h4>
<div class="c">桔红</div>
<h4>blue</h4>
<div class="c">蓝色</div>
<h4>green</h4>
<div class="c">绿色</div>
</div>
<script type="text/javascript">
function id(elem) {return document.getElementById(elem)} //获得id
function show(elem) {elem.style.display = "";} //展示
function hide(elem) {elem.style.display = "none";} //隐藏
//获得元素
function next( elem ) {
do {
elem = elem.nextSibling;
} while ( elem && elem.nodeType != 1 );
return elem;
}//tab("tab",{e:"onmouseover",n:2});
function tab(a, p) {
var p = (p === undefined) ? {e:"onclick",n:1} : p,
node = id(a).firstChild,
x = [];
p.e = (p.e === undefined) ? "onclick" : p.e;
p.n = (p.n === undefined) ? 1 : p.n;
node=(node.nodeType !== 1)?next(node):node;
for (var i = 1, node; node; i++, node = next(node)) {
x[i] = node; //将元素装载到x[]中
}
// alert(x.length);
//alert(x[1].nodeType);
for (var i = 1; x[i]; i++) {
if(i % 2 == 0){ //偶数情况 tab头设置
hide(x[i]);
// x[i-1].id=a+(i/2) //为tab头设置id
}
x[p.n*2-1].className = "cur";
show(x[p.n*2]);
temp = function (i) {
if (i % 2 == 1) { //奇数情况 tab内容设置
x[i][p.e] = function () {
for (var j = 1; x[j]; j++) {
if (j % 2 == 0) {
hide(x[j]);
x[j-1].className = ""
}
}
show(x[i+1]);
x[i].className = "cur"
}
} else {
return null
}
}(i)
}
}
tab("tab",{e:"onmouseover",n:1});
tab("tab2",{e:"onmouseover",n:1});
tab("tab_")
</script>
</body>
</html>
改好了。
你把第二个tab的id改成其他的,如<dl id="tabxxx">,再使用tab("tabxxx",{e:"onmouseover",n:2})就可以了。
另外,{e:"onmouseover",n:2}这个配置参数中的e是操作时需要响应的事件,n为默认激活的tab
再发一个我格式化过的<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Tab选项卡和滑动门同时布局在一个页面上丨芯晴网页特效丨CsrCode.Cn</title>
<meta http-equiv="content-type" content="text/xml;charset=utf-8" />
<style type="text/css">
*{
margin:0;
padding:0;
font-size:13px;
line-height:1.5;
}
body{
padding:20px;
}
.cur{
color:#f60;
border-bottom:1px solid #fff;
font-weight:bold;
background:#fff;
cursor:default;
}
#tab_,dl{
position:relative;
float:left;
height:100px;
width:300px;
}
h4,dt{
float:left;
height:20px;
margin:0 0 0 8px;
display:inline;
line-height:20px;
width:60px;
border:1px solid #ccc;
position:relative;
z-index:11;
text-align:center;
font-weight:normal;
cursor:pointer;
background:#eee;
}
.c,dd{
position:absolute;
top:21px;
border:1px solid #ccc;
left:0;
width:250px;
padding:20px;
overflow:hidden;
display:block;
}
#tab_{
clear:left;
}
h1{
clear:left;
padding:10px 0
}
#tab_1.cur{
color:#f60
}
#tab_2.cur{
color:blue
}
#tab_3.cur{
color:green
}
</style>
</head>
<body>
<h1>mouseover</h1>
<dl id="tab">
<dt>美国</dt>
<dd>我都不怕</dd>
<dt>朝鲜</dt>
<dd>谁都怕我</dd>
<dt>某国</dt>
<dd>我谁都怕</dd>
</dl>
<h1>mouseover</h1>
<dl id="tabx">
<dt>美国</dt>
<dd>我都不怕</dd>
<dt>朝鲜</dt>
<dd>谁都怕我</dd>
<dt>某国</dt>
<dd>我谁都怕</dd>
</dl>
<h1>click</h1>
<div id="tab_">
<h4>orange</h4>
<div class="c">桔红</div>
<h4>blue</h4>
<div class="c">蓝色</div>
<h4>green</h4>
<div class="c">绿色</div>
</div>
<script type="text/javascript">
function id(elem) {
return document.getElementById(elem)
}
function show(elem) {
elem.style.display = "";
}
function hide(elem) {
elem.style.display = "none";
}
function next(elem) {
do {
elem = elem.nextSibling;
} while (elem && elem.nodeType != 1);
return elem;
}
function tab(a, p) {
var p = (p === undefined) ? {
e : "onclick",
n : 1
} : p,
node = id(a).firstChild,
x = [];
p.e = (p.e === undefined) ? "onclick" : p.e;
p.n = (p.n === undefined) ? 1 : p.n;
node = (node.nodeType !== 1) ? next(node) : node;
for (var i = 1, node; node; i++, node = next(node)) {
x[i] = node;
}
for (var i = 1; x[i]; i++) {
console.log()
if (i % 2 == 0) {
hide(x[i]);
x[i - 1].id = a + (i / 2)
}
x[p.n * 2 - 1].className = "cur";
show(x[p.n * 2]);
temp = function (i) {
if (i % 2 == 1) {
x[i][p.e] = function () {
for (var j = 1; x[j]; j++) {
if (j % 2 == 0) {
hide(x[j]);
x[j - 1].className = ""
}
}
show(x[i + 1]);
x[i].className = "cur"
}
} else {
return null
}
}
(i)
}
}
tab("tab", {
e : "onmouseover",
n : 2
});
tab("tabx", {
e : "onmouseover",
n : 1
});
tab("tab_")
</script>
</body>
</html>
请问一下,他这个是如何实现tab方法内部自动生成的id的啊 没太看懂 谢谢
hide(x[i]);
x[i - 1].id = a + (i / 2)
//这一行,a是整个tabpanel的id,其实就是给tabpanel的头部用a+(1...n)的方式依次赋值
}另外,格式化过的代码我多写了一个console.log(),删掉就可以,不然ie下报错