Firefox ignores option selected=“selected”

前端 未结 20 1600
你的背包
你的背包 2020-11-28 21:59

If you change a dropdown and refresh the page, Firefox seems to ignore the selected attribute.

20条回答
  •  渐次进展
    2020-11-28 22:36

    This is my solution:

    var select = document.getElementById('my_select');
    for(var i=0; i < select.options.length; i++){
        select.options[i].selected = select.options[i].attributes.selected != undefined;
    }
    

    I just put that at the top of the page (with appropriate id set), and it works for me. Replacing the getElementById with a loop over all selects on the page, I leave as an exercise for the reader ;).

提交回复
热议问题