Firefox ignores option selected=“selected”

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

    AFAIK, this behaviour is hard-coded into Firefox.

    You could try setting each form element to its defaultValue on page load.

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

    autocomplete wasn't working for me either.

    This is the javscript fix written in jquery that i use:

    $('input[type="radio"][selected]').click();
    
    0 讨论(0)
  • 2020-11-28 22:28

    To show the first item of the dropdown, use ProjectName.ClearSelection();

    Put lines in your design page to work on all browser And also put this on code behind on page load.

    $(document).ready(function () {
        $("#content_ProjectName option[value='1']").prop("selected", true);
    });
    
    0 讨论(0)
  • 2020-11-28 22:31
    <option selected="selected" value="Test">Test</option>
    

    In this case this worked both for Chrome and Firefox.

    $('option[value="Test"]').prop('selected', true);
    

    I was using .attr() instead of .prop()

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

    If you change the select and refresh the page firefox will restore your changes on the form, that's why you feel like the select isn't working. Instead of refreshing, try opening the link on a new tab.

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

    use .prop() instead of .attr()

    This does not work in firefox.
      $( 'option[value="myVal"]' ).attr( 'selected', 'selected' );
    use this one
      $( 'option[value="myVal"]' ).prop( 'selected', 'selected' );
    
    In other way
      $( this ).prop( 'selected', 'selected' );
    
    0 讨论(0)
提交回复
热议问题