jQuery selector for select elements with empty value attributes?

后端 未结 3 1272
挽巷
挽巷 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 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(...)
    

提交回复
热议问题