我有以下代码
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>
</head>
<body style="background-color:yellow;width:100%;height:100%;">
<a href="javascript:test()">test</a>
<script>
function test() {
$("body").css("cursor","wait"); //cursor must be changed here
$.ajax(...);
}
</script>
</body>
</html>
此代码的问题在于,仅当函数 test()
完成时,光标才会在浏览器中从 default
更改为 wait
,但我需要它改变某些功能点。我在 Ubuntu 14 的 FF 58 和 Windows 7 的 Opera 中尝试过。我已经阅读了很多关于它的帖子并尝试了这个解决方案
$(document).ajaxStart(function() {
$(document.body).css({'cursor' : 'wait'});
}).ajaxStop(function() {
//$(document.body).css({'cursor' : 'default'});
});
但没有成功。如何解决?有什么想法吗?
最佳答案
我找到了答案。我在我的 ajax async:false
-
$.ajax({ ...
async: false,
...
});
当我改成
$.ajax({ ...
async: true,
...
});
一切开始按预期工作。
关于javascript - JS 仅在 js 功能完成时更改光标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49705940/