2012-02-25 15 views
6

我遇到了這個問題,並且從一些谷歌搜索中我意識到這可能是Chrome和Safari瀏覽器中的一個錯誤。使用AjaxStop事件完成ajax調用後(在Chrome中)將等待光標更改爲默認(自動)

當我提交表單(基本上,做一個ajax調用)時,默認光標變爲等待光標(沙漏),並且當ajax調用完成(響應)時,光標變爲默認類型(箭頭)。但是,這隻適用於IE和FF。在Chrome中,光標仍然是沙漏光標,直到我做類似移動光標或有警告等。

我嘗試了一個解決方案,非常類似於使用Jquery的Ajax停止和啓動事件觸發的here行動,但由於某種原因,它不適合我。

下面是我的jsp/html代碼。

function SubmitForm() 
{ 
    globalAjaxCursorChange(); 
    // some code to make Ajax call 
} 

function globalAjaxCursorChange() 
{ 
    $("html").bind("ajaxStart", function(){ 
     $(this).addClass('busy'); 
    }).bind("ajaxStop", function(){ 
     $(this).removeClass('busy'); 
    }); 
} 

這是我的CSS代碼。

html.busy, html.busy * { 
    cursor: wait !important; 
} 

我在想什麼或我在哪裏錯了?文章中提到的解決方案似乎對我來說很直接,但不起作用。非常感謝您的任何建議。

+0

任何 - 任何建議? – user1006072 2012-02-27 21:05:54

+0

我想知道這個答案。 – Andrew 2012-06-29 04:12:21

回答

1

我不確定爲什麼.bind變體不起作用,但當我爲「jquery bind ajaxStart」搜索時,this是第一個搜索結果。

因此,只有最微小的變化(即,改變.bind("ajaxStart",.ajaxStart(ajaxStop一樣),我有你的代碼工作,如下圖所示:

$(document).ready(function() { 
    // Global ajax cursor change 
    $("html") 
     .ajaxStart(function() { 
      $(this).addClass('busy'); 
     }) 
     .ajaxStop(function() { 
      $(this).removeClass('busy'); 
     }); 
}); 
0

在jQuery的1.9你should attach them to document

// Makes the mousecursor show busy during ajax 
// 
$(document) 

    .ajaxStart(function startBusy() { $('html').addClass ('busy') })  
    .ajaxStop (function stopBusy() { $('html').removeClass('busy') })