Check if textbox has empty value

后端 未结 8 2080
感情败类
感情败类 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:53

    if (inp.val().length > 0) {
        // do something
    }
    

    if you want anything more complicated, consider regex or use the validation plugin which takes care of this for you

提交回复
热议问题