Firefox ignores option selected=“selected”

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

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

20条回答
  •  萌比男神i
    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' );
    

提交回复
热议问题