How do you select a particular option in a SELECT element in jQuery?

前端 未结 21 2100
Happy的楠姐
Happy的楠姐 2020-11-22 10:55

If you know the Index, Value or Text. also if you don\'t have an ID for a direct reference.

This, this and this are all helpful answers.

Example markup

21条回答
  •  半阙折子戏
    2020-11-22 11:21

    By value, what worked for me with jQuery 1.7 was the below code, try this:

    $('#id option[value=theOptionValue]').prop('selected', 'selected').change();
    

提交回复
热议问题