我为 div:target
编写了一些特殊样式.当我点击 <a href="#target">
时,Chrome、Firefox 和 IE9+IE11 运行良好.现在我点击后退按钮(或“javascript: history.go(-1)
”),我的 URL 栏立即返回,但 IE 拖着脚回到默认样式,有时需要 3-5 秒,有时它根本不更新,直到我按下 F12 并尝试检查有问题的元素(然后它立即更新)。给了什么?
更新:这似乎只发生在 IE11 中。每个人 w/( native 安装)IE9 都没有问题。即使用 IE11 模拟 IE9 也会有问题。
http://jsfiddle.net/r1rqp1sc/2/ :
$('#hello').click(function(){
history.go(-1);
});
div {
width: 100px; height: 100px;
background: gray; color: white;
cursor: pointer;
}
div:target { background: red; }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<a href="#hello">Hello</a>
<div id="hello">Click here to go history:back()</div>
最佳答案
所以这并没有回答问题,但似乎与IE11在遍历历史后没有有效地重绘有关。显然,只需在该元素上添加或删除一个类就会强制重绘该元素。
$('#hello').click(function(){
history.go(-1);
$(this).addClass('z').removeClass('z');
});
关于css - `:target` 样式在 IE11 中表现异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32746614/