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

前端 未结 21 1988
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:40

    I use this, when i know the index of the list.

    $("#yourlist :nth(1)").prop("selected","selected").change();
    

    This allows the list to change, and fire the change event. The ":nth(n)" is counting from index 0

提交回复
热议问题