How to add “selected” in option attribute using Javascript or jQuery?

后端 未结 6 906
猫巷女王i
猫巷女王i 2021-02-09 02:16

Below is code for select option and generate using php from database and i try to add selected=\"selected\" to value=\"4\" using jQuery or any javascri

6条回答
  •  失恋的感觉
    2021-02-09 02:39

    As of jQuery 1.6 "To retrieve and change DOM properties such as the checked, selected, or disabled state of form elements, use the .prop() method."

    $("#countryselect option[value=4]").prop("selected", "selected")
    

提交回复
热议问题