Javascript 代码在IE中与Jquery不同步运行
我很难让IE同步运行jscript代码。其他浏览器没有问题。下面是一个代码示例:Javascript 代码在IE中与Jquery不同步运行,javascript,internet-explorer,jquery,Javascript,Internet Explorer,Jquery,我很难让IE同步运行jscript代码。其他浏览器没有问题。下面是一个代码示例: function renew_order() { $.ajaxSetup({async:false}); // These 3 lines are to disable 2 buttons and show a progress indicator. This never happens, // which is the main problem. $('#cancel_ord
function renew_order() {
$.ajaxSetup({async:false});
// These 3 lines are to disable 2 buttons and show a progress indicator. This never happens,
// which is the main problem.
$('#cancel_order_button').attr("disabled", "disabled");
$('#renew_order_button').attr("disabled", "disabled");
$('#renew_order_load').show();
// Make some Ajax call to do some processing
$.getJSON(url, function(json) {
$.each (json, function (type, name) {
new_order_id = json.OrderId;
});
});
// Close the modal box this is diaplyed on and display some results on the web page
$.modal.close();
display_new_order(order_list);
}
基本上,代码运行,模式框关闭,结果显示。但在进程运行时,模式框上的按钮从不显示为禁用。这似乎只是IE的一个问题。尝试改用prop函数
$(".example").prop("disabled", true);
如果这不起作用,你会怎么做
document.getElementById("example").disabled = true
我不认为这与同步性有任何关系,因为在ajax调用之前应该禁用按钮。在控制台窗口中检查javascript错误——我猜您在那里遇到了一些问题。这很讽刺。。。我昨天遇到了一个非常类似的问题,只影响IE。当我单击一个复选框时,我想禁用另一个复选框并更改相应标签中文本的颜色。由于某些原因,更改标签颜色的代码在IE中无法工作(其他浏览器没有问题)。最后,我们使用
setTimeout()
来延迟执行一行未正确执行且正常工作的代码。我很想知道我们为什么要这么做@jahroy—这无疑是因为在服务器返回数据之前,您试图使用与AJAX响应相关的数据。当您的服务器运行缓慢时,您的setTimeout将无法工作。@Adam-我的应用程序中没有ajax。我希望这是显而易见的。我说的是点击一个复选框并使其影响另一个复选框标签的颜色。当我有时间的时候,我会编一把小提琴,编一个问题。。。不幸的是,我们用了一个笨拙的变通方法来解决这个问题,我现在必须做些别的事情。当这个问题看起来可能有关联时,我很兴奋。为了证明我们的解决方案是多么愚蠢,只需要1毫秒
的延迟就可以让代码正常工作(这只在IE中是必需的)!!为了解释原因,这是我见过的最好的例子: