简体   繁体   English

将文本样式(类)恢复为原始样式 CSS

[英]Revert text-styling (class) back to it's original CSS

I have a span like this and styled as:我有一个这样的span ,样式如下:

<span class="spoiler" onclick="reveal()"> I am a sentence.</span>

.spoiler {
  background-color:#000000;
}

.spoiler:hover{
  background-color:transparent;
  }

Then I have some JS that modifies to permanently reveal the hidden text (truncated to show relevant part only):然后我有一些 JS 修改以永久显示隐藏文本(截断以仅显示相关部分):

if ... {
        sentence.style.color = "#f00";
        sentence.style.backgroundColor = "transparent";
    } else {
        sentence.style.color = "#000";
        sentence.style.backgroundColor = "#000000";
    }

The problem is in the else .问题出在else Once I click to revert back to the spoiler style, I can no longer hover over the text to reveal the sentence (as I could pre-click).一旦我点击恢复剧透风格,我就不能再通过hover在文本上显示句子(因为我可以预先点击)。

How to achieve this?如何做到这一点?

Instead of set style on span in 'if' add some class on it, and remove this class in 'else'.而不是在“if”中设置跨度样式,在其上添加一些 class,并在“else”中删除此 class。 Or just remove style attribute in else.或者只是删除 else 中的样式属性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM