Check if value is in select list with JQuery

前端 未结 7 2417
小蘑菇
小蘑菇 2020-12-13 17:06

How can I, using JQuery, check if a value belongs to dropdown list or not?

相关标签:
7条回答
  • 2020-12-13 17:27

    Just in case you (or someone else) could be interested in doing it without jQuery:

    var exists = false;
    for(var i = 0, opts = document.getElementById('select-box').options; i < opts.length; ++i)
       if( opts[i].value === 'bar' )
       {
          exists = true; 
          break;
       }
    
    0 讨论(0)
提交回复
热议问题