[英]How do i give my link a color when clicked
Hy, HY,
I'm currently working on this website and i need to be able to click on a link en that should open a div en close again when clicked. 我目前正在该网站上工作,我需要能够单击一个链接,该链接应该会在单击时再次打开div并关闭。 This i've already done. 我已经做完了。 But my question is how do i make the link stay #0083ce when clicked. 但是我的问题是,单击该如何使链接保持为#0083ce。 I've tried somethings but they do not seem to work together with my other javascript (for the div's). 我已经尝试了一些方法,但是它们似乎无法与其他javascript(对于div)一起使用。
function newwindow1(ele) {
var links = ['Profiel','Verbinder','Plaatjes','Moeren','Bouten','Scharnieren',
'Stelvoeten','Montage','Joints','Afdekken','Netten','Rails','Shuiven',
'Toebehoren','Quickboy'];
var srcElement = document.getElementById(ele);
var doShow = true;
if(srcElement != null && srcElement.style.display == "block")
doShow = false;
for( var i = 0; i < links.length; ++i ) {
var otherElement = document.getElementById(links[i]);
if( otherElement != null )
otherElement.style.display = 'none';
}
if( doShow )
srcElement.style.display='block';
return false;
}
css CSS
a:visited {
color:#0083ce;
}
Visited css selector 访问过的CSS选择器
a:active {
color:#0083ce;
}
Active for when you actually click down on a link. 当您实际单击链接时有效。
You can simply use :visited, :active values to set required colour. 您可以简单地使用:visited和:active值来设置所需的颜色。 eg: 例如:
.classname:active { color: #994; /*any color*/ } .classname:visited { //color: #F00; /*any color*/ }
<a class="classname" href="#">Test</a>
Please refer link for getting different colors 请参考链接获得不同的颜色
http://www.w3schools.com/css/css_link.asp http://www.w3schools.com/css/css_link.asp
If you want to use a CSS rule, define a style called .active
, for example: 如果要使用CSS规则,请定义一个名为.active
的样式,例如:
.active { color: #0083ce; }
In you JavaScript, you need to set a class to active on srcElement
and make sure to remove that class in the otherElement
loop. 在JavaScript中,您需要将一个类设置为在srcElement
上处于活动状态,并确保在otherElement
循环中删除该类。
You need to use something like srcElement.className
. 您需要使用srcElement.className
类的srcElement.className
。
Reference: https://developer.mozilla.org/en-US/docs/Web/API/Element/className 参考: https : //developer.mozilla.org/zh-CN/docs/Web/API/Element/className
function newwindow1(ele) { var links = ['Profiel','Verbinder','Plaatjes','Moeren','Bouten','Scharnieren', 'Stelvoeten','Montage','Joints','Afdekken','Netten','Rails','Shuiven', 'Toebehoren','Quickboy']; var srcElement = document.getElementById(ele); var doShow = true; if(srcElement != null && srcElement.style.display == "block") doShow = false; for( var i = 0; i < links.length; ++i ) { var otherElement = document.getElementById(links[i]); if( otherElement != null ) otherElement.style.display = 'none'; } if( doShow ) { srcElement.style.display='block'; srcElement.className='active'; } return false; }
.active {color: blue;}
<div id="Profiel" onclick="newwindow1('Profiel');">Profiel</div> <div id="Verbinder" onclick="newwindow1('Verbinder');">Verbinder</div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.