以下标签适用于外部js文件。如何添加链接,以便当用户点击链接www.ll.com/#comments时,他会看到评论.tab http://www.dynamicdrive.com/dynamicindex17/tabcontent/tabcontent.js
<ul id="countrytabs" class="shadetabs">
<li><a href="#movies" rel="tutorial" class="selected">Tutorial</a></li>
<li><a href="#Comments" rel="comments">Comments</a></li>
</ul>
<div class="contentbox">
<div id="movies" class="tabcontent">
Download movies here
</div>
<div id="comments" class="tabcontent">
</div>
<script type="text/javascript">
var countries=new ddtabcontent("countrytabs")
countries.setpersist(true)
countries.setselectedClassTarget("link") //"link" or "linkparent"
countries.init()
</script>
答案 0 :(得分:0)
在countries.init()
之后尝试此操作:
var tagIndex = window.location.toString().indexOf('#');
if (tagIndex >= 0)
countries.expandit(window.location.toString().substring(tagIndex).toLowerCase());
编辑:您在提供的示例代码中遇到了一些问题(您没有等待文档onload事件。您没有像ddtabcontent文档站点那样遵循A链接的命名约定,...)
我创建了这个示例来测试其功能:
<html>
<head>
<script type="text/javascript" src="tabcontent.js"></script>
<script type="text/javascript">
function onload()
{
var countries = new ddtabcontent("countrytabs");
countries.setpersist(true);
countries.setselectedClassTarget("link");
countries.init();
var url = window.location.toString();
var tagIndex = url.indexOf('#');
if (tagIndex >= 0)
countries.expandit(url.substring(tagIndex).toLowerCase());
}
</script>
<style type="text/css">
div.tabcontent
{
display: none;
}
</style>
</head>
<body onload="onload()">
<ul id="countrytabs" class="shadetabs">
<li><a href="#movies" id="#movies" rel="movies" class="selected">Movies</a></li>
<li><a href="#comments" id="#comments" rel="comments">Comments</a></li>
</ul>
<div class="contentbox">
<div id="movies" class="tabcontent">
Download movies here
</div>
<div id="comments" class="tabcontent">
Put comments here
</div>
</div>
</body>
</html>