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

前端 未结 21 1970
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:33

    For Jquery chosen if you send the attribute to function and need to update-select option

    $('#yourElement option[value="'+yourValue+'"]').attr('selected', 'selected');
    $('#editLocationCity').chosen().change();
    $('#editLocationCity').trigger('liszt:updated');
    

提交回复
热议问题