Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/89.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript JS仅在JS函数完成时更改光标_Javascript_Jquery_Html_Ajax - Fatal编程技术网

Javascript JS仅在JS函数完成时更改光标

Javascript JS仅在JS函数完成时更改光标,javascript,jquery,html,ajax,Javascript,Jquery,Html,Ajax,我有以下代码 <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

我有以下代码

<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>

但是没有成功。如何修复它?有什么想法吗?

在发送之前,您可以这样使用:

$.ajax({
beforeSend:function(){
//处理beforeSend事件
},
完成:函数(){
//处理整个事件
}
//……在此处输入代码`
});

注意-如您所做的那样将光标设置为document.body意味着它将只应用于document,而不应用于其他dom元素,如anchor、textbox等我找到了答案。我在我的ajax
async:false
-

$.ajax({ ...
     async: false,
      ...     
});
当我换成

$.ajax({ ...
     async: true,
      ...     
});

一切都按预期开始工作。

那么期望的行为是什么??你说“我需要它来改变某些功能点。”你的意思是在ajax调用之前可能吗?@jonhid I editedI也编辑了我的问题!:-)@jonhid是的,我在代码中显示了什么。请参阅test()函数。您是否使用jQeury进行ajax调用?
$.ajax({ ...
     async: false,
      ...     
});
$.ajax({ ...
     async: true,
      ...     
});