【问题标题】:Toggle pseudo class :after on specific div切换伪类:在特定 div 之后
【发布时间】:2013-03-23 21:26:20
【问题描述】:

如何启用或禁用(或切换)'after' 伪类?

我试图想出一些类似的东西:

$('.card').click(function(){

    if(pick1) {
        pick2 = $(this).css('background-color');
        id2 = $(this).attr('id');
        >>> add display:none to .card:after for the clicked div <<<

        if(pick1 == pick2 && id1!=id2) alert('Correct');
            else {
                alert('Incorrect');
                >>> remove display:none from .card:after on clicked divs <<<
            }

        pick1 = false;
        pick2 = false;
    } else {
        pick1 = $(this).css('background-color');
        id1 = $(this).attr('id');
        >>> add display:none to .card:after for the clicked div <<<  
    }
});

我的项目在这里:http://jsfiddle.net/94jerdaw/29TCZ/3/

【问题讨论】:

  • 您能解决您的问题吗?
  • 是的,谢谢 :) 我创建了一个单独的课程并在需要的地方添加/删除了它。
  • 太棒了。如果我的回答对您有帮助,请随时接受,以便其他人知道问题已得到解决。

标签: javascript jquery css class html


【解决方案1】:

你为什么不在规则中添加一个额外的类?像这样

.hidden.card:after{
  display:none
}

那么代码可以是$().addClass("hidden")$().removeClass("hidden")

if(pick1) {
    pick2 = $(this).css('background-color');
    id2 = $(this).attr('id');
    $(this).addClass("hidden");

    if(pick1 == pick2 && id1!=id2) alert('Correct');
        else {
            alert('Incorrect');
            $(this).removeClass("hidden");
        }

    pick1 = false;
    pick2 = false;
} else {
    pick1 = $(this).css('background-color');
    id1 = $(this).attr('id');
    $(this).addClass("hidden"); 
}

【讨论】:

  • 这个。因为据我所知,您无法通过嘶嘶声在本机访问伪选择器。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-03-19
  • 2018-11-19
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多