1

我正在制作一个关于讲座的网站。讲座分为章节。每章都有自己的链接,当点击一个新视频时,一个外部 html 会加载到一个文本窗口中。我需要这些链接保持活跃,以便人们知道他们在哪一章。

这是我当前的html:

<li><a href="#" onclick="javascript:loadContent('#pres', chapter1.html');changeVideo('chapter1')">chapter1</a></li>
<li><a href="#" onclick="javascript:loadContent('#pres', 'chapter2.html');changeVideo('chapter2')">chapter2</a></li>

..等等..

现在,这很完美。正如我所说,我需要链接保持活动状态,并尝试添加一个 addClass(this) IE:

onclick="javascript:loadContent('#pres','chapter2.html');changeVideo('chapter2');addClass(this)">... 

function addClass(obj)
{
  obj.className="active";
}

这行不通。我也尝试删除除了 addClass 函数之外的所有内容,但没有成功。

有任何想法吗?

4

2 回答 2

1
function clickChapter(type, page, chapter){
    loadContent(type, page);
    changeVideo(chapter);
    removeAllClass();
    addClass(ocument.getElementById('id_'+chapter));
}

function removeAllClass(){
    var aAnchor = document.getElementsByTagName('A');
    for(var i=0; i<aAnchor.length;  i++){
        aAnchor[i].className = '';
    }
}

<li><a href="#" id="id_chapter1" onclick="clickChapter('#pres', 'chapter1.html', 'chapter1')">chapter1</a></li>
<li><a href="#" id="id_chapter2" onclick="clickChapter('#pres', 'chapter2.html', 'chapter2')">chapter2</a></li>
于 2012-08-09T09:54:41.437 回答
0

你可以试试这个...

首先创建一个级联样式表(CSS)并在其中编写如下代码:

a:active {
    color: #006600;
    font: 12px Verdana, Arial, Helvetica, San-serif;
    text-decoration: none;
}

或者

a:visited {
    color: #006600;
    font: 12px Verdana, Arial, Helvetica, San-serif;
    text-decoration: none;
}

或者

a:link {
    color: #006600;
    font: 12px Verdana, Arial, Helvetica, San-serif;
    text-decoration: none;
}

然后将此代码粘贴到您的 html 页面的头部:

 <link type="text/css" href="<Path of the CSS>.css" rel="stylesheet"/>
于 2012-08-09T09:43:02.603 回答