jQuery check if <input> exists and has a value

后端 未结 7 777
情歌与酒
情歌与酒 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 01:10

    You can do something like this:

    jQuery.fn.existsWithValue = function() { 
        return this.length && this.val().length; 
    }
    
    if ($(selector).existsWithValue()) {
            // Do something
    }
    

提交回复
热议问题