开发者

How to select textboxes that have a length > 0 with jquery?

How would I write a selector that would look through say a div of textboxes and find which ones have开发者_如何学Go a value in the textbox(so length would be greater than zero).

Can I do this all in one selector or do I have to get all textboxes then loop through them?


$('textarea[value!=""]')

Of course, if it's an input, you can just modify it:

$('input:text[value!=""]')


$("input:text").filter(function() { return $(this).val().length > 0; })

The filter function allows you to provide a custom function which will be called with each currently selected element as this, and only the elements for which it returns true will stay in the set.


Following should work:

nonempty_inputs = $(':input:not(:empty)');

If it's only textareas you are interested in, just change :input to textarea

See also:

  • http://api.jquery.com/empty-selector/
  • http://api.jquery.com/input-selector/
  • http://api.jquery.com/not-selector/


$('input[value!=""]')


You can do like:

$('input[type="text"]').each(function(){
  if ($(this)).val().length > 0)
  {
     alert('I have value !!');
  }
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜