Select box truncating text when body font size changed via javascript on document ready in IE 9

后端 未结 5 771
余生分开走
余生分开走 2021-01-02 02:59

IE 9 is behaving quite strangely for me. I\'ve got a page font-size changing control that saves the users setting and then in the document ready sets the body font-size to

5条回答
  •  忘掉有多难
    2021-01-02 03:08

    Select boxes in IE suffer from a long and unfortunate history of extraordinary bugs.

    In the days of IE6, the select box was a windowed OS control—a wrapper for the Windows Shell ListBox that existed in a separate MSHTML plane from most other content.

    In IE 7, the control was rewritten from scratch as an intrinsic element rendered directly by the MSHTML engine. This helped with some of the more prominent bugs, but some of this unhappy legacy remains. In particular: after a select box is drawn, changes via the DOM do not always propagate as one might expect.

    Here, each option in the select list is drawn to exactly the right width for the text it contains when the control is first rendered. When you increase the text size of the page, IE correctly propagates the change to the control itself but does not adjust the width of the options, so text starts overflowing to the next line:

    Select box overflowing to the next line in IE9.

    You can fix this by forcing a repaint of the select box. One way to do this is to append a single space character to the select element:

    $('select').append(' ');
    

    Alternatively, you could change the style attribute:

    $('select').attr('style', '');
    

    Of these, the .append() strategy has the fewest potential side effects and enforces better separation of style and behaviour. (Its essential impact on the DOM is nil.)

提交回复
热议问题