强制在IE中重新应用样式表 [英] Forcing to re-apply a style sheet in IE

查看:116
本文介绍了强制在IE中重新应用样式表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请考虑这个HTML:

<ul>
<li>first</li>
<li>second</li>
<li>third</li>
</ul>

此CSS:

li:first-child { background: yellow; }

和此Javascript(jQuery):

And this Javascript (jQuery):

$("ul").append($("li:first-child"));

http://fiddle.jshell.net/Xtuaf/

显然位于 Internet Explorer (8):first-child 在DOM更改时断开。我在Javascript中写了一个这个问题的解决方法(做样式; z-index 在我的case)。这是一个丑陋的快速修复,我想摆脱。更好的解决方案是强制在DOM更改时重新应用样式表。这可以做吗?

Apparently in Internet Explorer (8) :first-child breaks when the DOM has changed. I wrote a workaround for this problem in Javascript (doing styling there; z-indexes in my case). It's an ugly quick fix that I want to get rid of. A better solution would be forcing to re-apply the style sheet when the DOM changes. Can this be done? Or is there an other solution to this problem?

推荐答案

在Internet Explorer中,可以通过设置类名来触发回流:

In Internet Explorer, a reflow can be triggered by setting the class name:

$("ul").append($("li:first-child")).addClass('x').removeClass('x');

或只是(demo: http://fiddle.jshell.net/Xtuaf/1/ ):

Or just (demo: http://fiddle.jshell.net/Xtuaf/1/):

$("ul").append($("li:first-child"))[0].className += '';

这篇关于强制在IE中重新应用样式表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆