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

前端 未结 21 1975
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:27

    Using jquery-2.1.4, I found the following answer to work for me:

    $('#MySelectionBox').val(123).change();
    

    If you have a string value try the following:

    $('#MySelectionBox').val("extra thing").change();
    

    Other examples did not work for me so that's why I'm adding this answer.

    I found the original answer at: https://forum.jquery.com/topic/how-to-dynamically-select-option-in-dropdown-menu

提交回复
热议问题