jQuery Loop through selects and set selected option

后端 未结 3 689
不思量自难忘°
不思量自难忘° 2021-01-29 14:05

I\'d like to loop through all of the select inputs on a page and if the selected value is not a certain option then set that value to selected

I have some selects

<
3条回答
  •  隐瞒了意图╮
    2021-01-29 14:16

    You can pass the desired option value to .val() method while targeting select to select required option element:

    $('select').val('2');
    

    Working Snippet:

     $('select').val('2');
    
    
    
    
    
    

提交回复
热议问题