2012-08-09 84 views
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

你还设置了'active'类的CSS?类'.active'和伪类':active'不一样。 – 2012-08-09 09:18:06

+0

我做了,虽然拼错了,但它并没有帮助纠正这一点。 – mezzie 2012-08-09 11:10:35

回答

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> 
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"/>