简体   繁体   English

Javascript Jquery-更改标签颜色

[英]Javascript Jquery - Change Label Color

I have this code: 我有以下代码:

 jQuery('#novaPasse').on('keyup',function(){
            var pass = $(this).val();

            if (IsEnoughLength(pass) && HasMixedCase(pass) && HasNumeral(pass)){
                $('#forcaPasse').text('Palavra-Passe Muito Forte!');
                $('#forcaPasse').prev('label').css('color','#8EFA00');
            }else if (IsEnoughLength(pass) && HasMixedCase(pass)){
                $('#forcaPasse').text('Palavra-Passe Forte!');
                $('#forcaPasse').prev('label').css('color','#7CDB00');
            }else if (IsEnoughLength(pass) && HasNumeral(pass)){
                $('#forcaPasse').text('Palavra-Passe Moderada!');
                $('#forcaPasse').prev('label').css('color','#FC9C35');
            }else{
                $('#forcaPasse').text('Palavra-Passe Fraca!');
                $('#forcaPasse').prev('label').css('color','#FF0000');
            }
            });

The goal is to change the color along with the text. 目的是更改颜色以及文本。 Without the color code it works and it changes the text. 没有颜色代码,它将起作用,并且会更改文本。 But I want the text differently colored.The text appears but the color doesn't change. 但是我希望文本的颜色不同。文本出现了,但是颜色没有改变。 This is my Label 这是我的标签

<label id="forcaPasse"></label>

Does anyone know how to change the color of the font of the label? 有谁知道如何更改标签字体的颜色?

The solution is: I removed prev('label') 解决方法是:我删除了prev('label')

jQuery('#novaPasse').on('keyup',function(){
            var pass = $(this).val();

            if (IsEnoughLength(pass) && HasMixedCase(pass) && HasNumeral(pass)){
                $('#forcaPasse').text('Palavra-Passe Muito Forte!');
                $('#forcaPasse').css('color','#8EFA00');
            }else if (IsEnoughLength(pass) && HasMixedCase(pass)){
                $('#forcaPasse').text('Palavra-Passe Forte!');
                $('#forcaPasse').css('color','#7CDB00');
            }else if (IsEnoughLength(pass) && HasNumeral(pass)){
                $('#forcaPasse').text('Palavra-Passe Moderada!');
                $('#forcaPasse').css('color','#FC9C35');
            }else{
                $('#forcaPasse').text('Palavra-Passe Fraca!');
                $('#forcaPasse').css('color','#FF0000');
            }
            });

Now it works correctly! 现在它可以正常工作了!

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

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