How can I, using JQuery, check if a value belongs to dropdown list or not?
相关问题
- dropdown <select> for list.js
- There is no ViewData item with the key 'taskTy
- IE dropdown z-index bug
- Jquery - Get Text Between 2 Div Tags
- What is the use of (“*”) in jquery
相关文章
- Django: Replacement for the default ManyToMany Wid
- How do I find all elements that have a title attri
- ASP.Net MVC 3: optgroup support in Html.DropDownLi
- How to break a line in select2 dropdown?
- Does jQuery always return array?
- JS/Jquery: how to check whether dropdown has selec
- Zend Framework 2 Forms Array notation for drop dow
- Adding jQuery Drop Downs to a Variable Length Data
Here is another similar option. In my case, I'm checking values in another box as I build a select list. I kept running into undefined values when I would compare, so I set my check this way:
I've no idea if this approach is more expensive.
Use the Attribute Equals Selector
If the option's value was set via Javascript, that will not work. In this case we can do the following:
Just in case you (or someone else) could be interested in doing it without jQuery:
Why not use a filter?
Loose comparisons work because exists > 0 is true, exists == 0 is false, so you can just use
Or combine it:
Or where each select dropdown has the select-boxes class this will give you a jquery object of the select(s) which contain the value: