jQuery Cannot set “selected”=“selected” via attr() on

前端 未结 3 1943
星月不相逢
星月不相逢 2020-12-05 16:23


$(\'.test\').         


        
3条回答
  •  攒了一身酷
    2020-12-05 16:44

    The selected attribute does not correspond to the current selectedness state of the option. The selected attribute corresponds to the default selectedness, which will be restored if .reset() is called (or a type="reset" button is clicked) on the form. The current selectedness state can be accessed using the DOM property selected, whereas the default-selectedness, as reflected by the attribute, is accessed under the DOM property defaultSelected.

    The same goes for value vs defaultValue on /