问题描述
这是情况。我有一些这样的javascript:
Here is the situation. I have some javascript that looks like this:
function onSubmit() {
doSomeStuff();
someSpan.style.display="block";
otherSpan.style.display="none";
return doLongRunningOperation;
}
当我提交表单提交操作,并从非IE运行它浏览器,它可以快速地切换两个跨度的可见性,并运行长时间的JavaScript操作。如果我在IE中执行此操作,直到onSubmit()完全返回后才会执行交换。
When I make this a form submit action, and run it from a non IE browser, it quickly swaps the two spans visibility and run the long javascript operation. If I do this in IE it does not do the swap until after onSubmit() completely returns.
我可以通过粘贴警报框来强制重新绘制:
I can force a dom redraw by sticking an alert box in like so:
function onSubmit() {
doSomeStuff();
someSpan.style.display="block";
otherSpan.style.display="none";
alert("refresh forced");
return doLongRunningOperation;
}
此外,明显的jQuery重构不会影响IE的行为:
Also, the obvious jquery refactoring does not affect the IE behavior:
function onSubmit() {
doSomeStuff();
$("#someSpan").show();
$("#otherSpan").hide();
return doLongRunningOperation;
}
此行为存在于IE8和IE6上。有没有办法在这些浏览器中强制重绘DOM?
This behavior exists on IE8 and IE6. Is there anyway to force a redraw of the DOM in these browsers?
推荐答案
你的longRunningOperation可以异步调用吗?
Can your longRunningOperation be called asynchronously?
这篇关于在JavaScript dom操纵后强制在Internet Explorer中进行DOM刷新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!