Check if textbox has empty value

后端 未结 8 2077
感情败类
感情败类 2020-11-30 23:19

I have the following code:

var inp = $(\"#txt\");

if(inp.val() != \"\")
// do something

Is there any other way to check for empty textbox

8条回答
  •  春和景丽
    2020-11-30 23:44

    var inp = $("#txt").val();
    if(jQuery.trim(inp).length > 0)
    {
       //do something
    }
    

    Removes white space before checking. If the user entered only spaces then this will still work.

提交回复
热议问题