0

以下选项卡适用于外部 js 文件。如何添加链接,以便当用户单击链接 www.ll.com/#comments 时,他将看到评论..tab http://www.dynamicdrive.com/动态索引17/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>
4

1 回答 1

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>
于 2012-06-03T17:04:54.723 回答