当onkeyup时,Jquery文本隐藏并显示

时间:2022-12-01 13:43:48

i want to use jquery text show and hide when onkeyup.

我想在onkeyup上使用jquery文本显示和隐藏。

but it doesn't work

但它不起作用

this is my code.

这是我的代码。

this is my jquery

这是我的jquery

Auth.joinCheck = function(mode){

var param;
var password1 = $("#userpasswordPre").val();
var password2 = $("#userpasswordCon").val();

//check id

if(mode == 1){
    param =$("#username").val();
    if(param.length < 2){
        $("#joinNav div.msgRow").show();
        $("#joinNav button.btnJoin").prop("disabled",true);
    }
    else{
        $("#joinNav div.msgRow").hide();
        $("#joinNav button.btnJoin").prop("disabled",false);
    }
    return false;
}
else if(mode == 2){
    if(password1.length < 4){
        $("#joinNav div.msgRow1").show();
        $("#joinNav button.btnJoin").prop("disabled",true);
    }else{
        $("#joinNav div.msgRow1").hide();
        $("#joinNav button.btnJoin").prop("disabled",false);
    }
    return false;
}else if(mode == 3){
    if(password1 != password2){
        $("#joinNav div.msgRow2").show();
        $("#joinNav button.btnJoin").prop("disabled",true);
    }else{
        $("#joinNav div.msgRow1").hide();
        $("#joinNav button.btnJoin").prop("disabled",false);
    }

    return false;


}

}

this is my HTML code

这是我的HTML代码

        <div class="form-group joinName">
            <span>ID :</span><input type="text" class="form-control" id="username" onkeyup="Auth.joinCheck(1);" required />
        </div>
        <div class="msgRow">Id must be more than 4 letter</div>

and My css about msgRow:none;

和我的关于msgRow的css:无;

text.show() does work but type Id more than 4 letter,

text.show()确实有效但输入的ID超过4个字母,

text.hide() doesn't work...

text.hide()不起作用......

1 个解决方案

#1


1  

Check this fiddle.
I made some changes on the code.
https://jsfiddle.net/mkd68r8f/

检查这个小提琴。我对代码做了一些更改。 https://jsfiddle.net/mkd68r8f/

 document.getElementById("username").addEventListener("keyup", function () {
     Auth.joinCheck(1)
});

#1


1  

Check this fiddle.
I made some changes on the code.
https://jsfiddle.net/mkd68r8f/

检查这个小提琴。我对代码做了一些更改。 https://jsfiddle.net/mkd68r8f/

 document.getElementById("username").addEventListener("keyup", function () {
     Auth.joinCheck(1)
});