Firefox ignores option selected=“selected”

前端 未结 20 1448
你的背包
你的背包 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:41

    Try to disable autocomplete attribute of select input ... sometimes browser ignore select because of that

    0 讨论(0)
  • 2020-11-28 22:41

    Neither autocomplete="off" or placing it inside a form works for me.

    What worked was to only use the attribute selected with no "value" like this:

    <option @(Model.Source == TermSource.Instagram ? "selected" : "")>
        Instagram
    </option>
    <option @(Model.Source == TermSource.Facebook ? "selected" : "")>
        Facebook
    </option>
    

    so either it renders <option selected>...</option>, or just <option>...</option>

    0 讨论(0)
  • 2020-11-28 22:42

    At work, I just fixed a bug where the select box option displayed properly in Chrome but not in Firefox, on the same web page. It turned out to be something completely different than the problems above, but could possibly be a problem you are experiencing.

    In Chrome, the select box font-color was black. For some reason in Firefox, the select box inherited the font-color from the container, which was white. Once I added a CSS rule to force that select box font-color to be black, the value set was properly displayed.

    0 讨论(0)
  • 2020-11-28 22:44

    It's just Firefox remembering your previous selection when refreshing. Try a hard refresh instead.

    Also, same issue over here: https://stackoverflow.com/a/1505693/1069232

    Also see here: https://bugzilla.mozilla.org/show_bug.cgi?id=274795

    0 讨论(0)
  • 2020-11-28 22:44

    enclose select in form attribute and it will work.

    <!-- will not work in firefox -->
    <option selected="selected" value="Test">Test</option>
    

    and

    <!-- this will work in firefox -->
    <form>
     <option selected="selected" value="Test">Test</option>
    </form>
    
    0 讨论(0)
  • 2020-11-28 22:45

    Just had the same issue, believe me it's been more than 10 hours struggling with this stupid firefox behavior, i have 7 dropdowns, each of them will trigger an event and fill in 24 hidden inputs, so you can imagine having the right option selected with 24 wrong input values!!! the solution i finally found is to reset the form with Javascript adding this line of code:

    window.onload = function() { document.forms['MarkerForm'].reset(); };
    

    PS: the inputs have the values pulled from a database, so resetting the form does not empty any value but in a way tells firefox to go back the hell to selected=selected option!

    0 讨论(0)
提交回复
热议问题