Set select option 'selected', by value

后端 未结 28 2853
攒了一身酷
攒了一身酷 2020-11-22 10:40

I have a select field with some options in it. Now I need to select one of those options with jQuery. But how can I do that when I only know the

28条回答
  •  旧巷少年郎
    2020-11-22 11:24

    Use the change() event after selecting the value. From the docs:

    If the field loses focus without the contents having changed, the event is not triggered. To trigger the event manually, apply .change() without arguments:

    $("#select_id").val("val2").change();
    

    More information is at .change().

提交回复
热议问题