检查一个int输入长度

您好,我尝试在字段中的整数为4时隐藏组。

$( "#ssnInput" ).keyup(function() {
 if( $('#ssnInput').value.toString().length = 4 ) {
    $('#ssnInputGroup').style.display = "none";
    }
});

知道为什么这行不通吗?

评论
DJHongKong
DJHongKong

I believe that you are using jquery and so you should be doing .val() instead of .value.

In fact, I think you are mixing up the two things. Even where you are setting the display to none. It should just be .hide().

点赞
评论
laut
laut

你有逻辑上的问题

$('#ssnInput').value.toString().length = 4

应该

$('#ssnInput').value.toString().length == 4 // or ===
点赞
评论
DJHongKong
DJHongKong

First of all, you are missing =.

Secondly, you can use .val().

像这样:

$("#ssnInput").val().length
点赞
评论