我有简单的html页面,有3个标签:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head><title>idTabs</title>
<script type="text/javascript" src="http://www.sunsean.com/idTabs/jquery-1.2.3.pack.js"></script>
<script type="text/javascript" src="http://www.sunsean.com/idTabs/jquery.idTabs.min.js"></script>
</head><body style="background-color:White; color:Black">
<style type="text/css">
/* Jquery Tabbed Panels */
div.idTabs
{
float:left;
margin-top:30px;
}
.idTabs a
{
display: block;
padding: 10px;
color: #333;
background: #DDF1FF;
font: 11px Verdana, Geneva, sans-serif;
text-decoration: none;
border: none;
}
.idTabs a.selected
{
background: #FFF;
color: #333;
border-bottom: solid 1px #FFF;
z-index: 120;
}
</style>
<div class="vi_wrapper">
<div class="idTabs">
<ul style=" padding: 0px; position: relative; z-index: 100;">
<li style="display: block; list-style: none; float: left; background: #CCC; padding: 1px 1px 0px 1px; margin-right:4px;">
<a class="selected" href="#Tab1" name="Tab1">Tab1</a>
</li>
<li style="display: block; list-style: none; float: left; background: #CCC; padding: 1px 1px 0px 1px; margin-right:4px;">
<a href="#Tab2" name="Tab2">Tab2</a>
</li>
<li style="display: block; list-style: none; float: left; background: #CCC; padding: 1px 1px 0px 1px; margin-right:4px;">
<a href="#Tab3" name="Tab3">Tab3</a>
</li>
</ul>
<div class="items">
<div id="Tab1">
<div style="float:left">
Tab1
<br />
here is hash, and when you click on it - no tab:
<br />
<a href="#SomeHashTab1">Some Hash 1</a>
</div>
</div>
<div id="Tab2">
<div style="float:left">
Tab2
<br />
here is hash, and when you click on it - no tab:
<br />
<a href="#SomeHashTab2">Some Hash 2</a>
</div>
</div>
<div id="Tab3">
<div style="float:left">
Tab3
</div>
</div>
</div>
</div>
<script type="text/javascript">
$(".idTabs").idTabs(true, location.hash);
</script>
</div>
</body></html>
因此,每个标签都会在链接中打开哈希值(#Tab1,#Tab2,#Tab3),但是如果我将一些其他带有哈希的链接添加到标签内容中,它会打开一个空标签页。
如何跳过不是制表符哈希值的所有哈希值? 非常感谢!
答案 0 :(得分:0)
if($(location.hash).length) {
$(".idTabs").idTabs(true, location.hash);
}
编辑:不是'#'+location.hash
,因为location.hash
已经包含'#'
。
答案 1 :(得分:0)
只需将items
DIV 移到 idTabs
DIV即可。似乎该插件将选项卡绑定在所有包含哈希的链接上。
编辑:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head><title>idTabs</title>
<script type="text/javascript" src="http://www.sunsean.com/idTabs/jquery-1.2.3.pack.js"></script>
<script type="text/javascript" src="http://www.sunsean.com/idTabs/jquery.idTabs.min.js"></script>
</head><body style="background-color:White; color:Black">
<style type="text/css">
/* Jquery Tabbed Panels */
div.idTabs
{
float:left;
margin-top:30px;
}
.idTabs a
{
display: block;
padding: 10px;
color: #333;
background: #DDF1FF;
font: 11px Verdana, Geneva, sans-serif;
text-decoration: none;
border: none;
}
.idTabs a.selected
{
background: #FFF;
color: #333;
border-bottom: solid 1px #FFF;
z-index: 120;
}
.items {
clear: both;
}
</style>
<div class="vi_wrapper">
<div class="tabs-cont">
<div class="idTabs">
<ul style=" padding: 0px; position: relative; z-index: 100;">
<li style="display: block; list-style: none; float: left; background: #CCC; padding: 1px 1px 0px 1px; margin-right:4px;">
<a class="selected" href="#Tab1" name="Tab1">Tab1</a>
</li>
<li style="display: block; list-style: none; float: left; background: #CCC; padding: 1px 1px 0px 1px; margin-right:4px;">
<a href="#Tab2" name="Tab2">Tab2</a>
</li>
<li style="display: block; list-style: none; float: left; background: #CCC; padding: 1px 1px 0px 1px; margin-right:4px;">
<a href="#Tab3" name="Tab3">Tab3</a>
</li>
</ul>
</div>
<div class="items">
<div id="Tab1">
<div style="float:left">
Tab1
<br />
here is hash, and when you click on it - no tab:
<br />
<a href="#SomeHashTab1">Some Hash 1</a>
</div>
</div>
<div id="Tab2">
<div style="float:left">
Tab2
<br />
here is hash, and when you click on it - no tab:
<br />
<a href="#SomeHashTab2">Some Hash 2</a>
</div>
</div>
<div id="Tab3">
<div style="float:left">
Tab3
</div>
</div>
</div>
</div>
<script type="text/javascript">
$(".idTabs").idTabs(true, location.hash);
</script>
</div>
</body></html>