简体   繁体   English

重点:永远在课堂之上

[英]focus: always above the classes

I have a class and I have some validation (no non-numbers allowed (which is not here, but I capture it on the keypress method)). 我有一个类,并且有一些验证(不允许使用非数字(此处不是,但是我在keypress方法上捕获了它))。 However, if I have a class with focus: , it is always on the top level of css and I cannot override the settings temporarily. 但是,如果我有一个具有focus:的类,则它始终位于css的顶层,并且我不能暂时覆盖设置。 Is there a way to solve this? 有办法解决吗?

In this 在这

JSFiddle JSFiddle

I am expecting red border to come out immediately on the first keypress , however it is overridden with focus and only appears when I focus out. 我期望红色边框会在第一次keypress时立即出现,但是它会被焦点覆盖,并且仅在我聚焦时才会出现。

You can modify the class like this: 您可以像这样修改类:

.a {
    border:1px solid red !important;
}

!important will override the focus css. !important将覆盖focus css。

Demo: Fiddle 演示: 小提琴

Change your css | 更改您的CSS | Demo 演示版

.a{
    border:1px solid red !important;
}

and script , if you want to remove red border if user is out of focus of input box 和脚本,如果用户在输入框之外时要删除红色边框

   $('input').on("keypress", function(){
    $(this).addClass('a');

    });
    $('input').on("blur", function(){
    $(this).removeClass('a');

    })

Have you tried to add the !important statement? 您是否尝试添加!important语句? Try something like this: 尝试这样的事情:

input:focus{
    border:1px dashed yellow;
}

On JS you can do: 在JS上,您可以执行以下操作:

$(input).keypress(function(ev){
    var target = ev.target;
    $(target).css({
        borderColor: '#AA0000 !important'
    });
}

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

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