jQuery check if <input> exists and has a value

后端 未结 7 897
情歌与酒
情歌与酒 2021-02-01 00:07

I have the following example:


Is there a way to check if this element exists and ha

7条回答
  •  感情败类
    2021-02-01 00:56

    You could do:

    if($('.input1').length && $('.input1').val().length)
    

    length evaluates to false in a condition, when the value is 0.

提交回复
热议问题