English 中文(简体)
再次单击时如何将链接的颜色从黑到红修改为红色,然后返回为黑色
原标题:How to change color of a link from black to red and back to black when clicked again
  • 时间:2012-05-23 21:02:00
  •  标签:
  • javascript

情况是,我有一个从 A 到 Z 的索引, 当我点击一个字母时, 相应的 div 显示。 当同一个字母再次点击时, div 就会崩溃 。

我想做到的是,当我第一次单击一个字母时,它应该将上方垂直对齐索引中的字母颜色改为红色。当再次从红色回击到黑色时。

我找到的解决方案在单击另一封信时重置了颜色。 问题在于多个 divs 将会激活, 多字母应该红。 但是, 我无法让它工作 。

我知道刺绣是解决问题的办法,但我不是一个好 Java 编码员。 我尝试了内/外HTML, 并获得了EmplementbyID, 但每个图例都是失败的。

我希望有人能帮上忙 三个字母的简短解决办法就足够了

该代码可在“http://www.webpati.com/index.txt” rel=“nofollow”>http://www.webpati.com/index.txt 上找到。

提前感谢。

最佳回答

仅添加

$(this).toggleClass( active );

在您的 jQuery 单击功能的 jQuery 下方,并添加 cs 规则等

.slick-toggle { color: black; }
.slick-toggle.active { color: red; }

jsfidle

问题回答

谢谢你的回答,我写了下方粗体的代码,它有效了。

jQuery("a.slick-toggle").click(function () {

 if($(this).children("span").text() == "") {

    $(this).children("span").text(  );

      } else {

        $(this).children("span").text( Show );

      } 

var id = jQuery(this).attr( id );

jQuery("#slickbox" + id).fadeToggle({

speed:200,easing : "swing"})


**$(this).toggleClass( active );**

return false;

});




相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签