jQuery selector for select elements with empty value attributes?

后端 未结 3 1235
挽巷
挽巷 2021-01-13 13:17

I\'m using the below selector to get all the form inputs that are pre-populated with a value.

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

This works great a

相关标签:
3条回答
  • 2021-01-13 13:48
    $('select').has('option[selected="selected"]')
    

    will get the select element. jsFiddle example.

    0 讨论(0)
  • 2021-01-13 14:00

    For select you need to use a special selector made available by JQuery: :selected

    So

    $('#state option:selected').val()
    

    is the current selected value.

    If you need the do something on the select elements themself you could do something like:

    $('#select option:selected').parents('select').dosomething(...)
    
    0 讨论(0)
  • 2021-01-13 14:01

    value is not an attribute of select tag.

    So you need to try:

    var emptySelect = $('select').filter(function() {
                         return $.trim( $(this).val() ) == '';
                      });
    
    0 讨论(0)
提交回复
热议问题