2011-01-11 114 views
2

我試圖通過使用js爲MS CRM動態4.0更改鼠標的光標, 當我通過使用ajax調用方法,我想顯示鼠標光標作爲等待: 文檔.body.style.cursor = 「等待」; 但它不工作...我怎麼能做到這一點?由js改變鼠標的光標

+0

您可以發佈您的任何代碼?從包含的單行看,該語法看起來是正確的。 – elwyn 2011-01-11 19:42:46

+0

它有些像這樣:function BaforeCallingAjaxMethod(){document.body.style.cursor =「wait」; CallAjaxMethodNow();} – 2011-01-11 20:52:52

回答

4

你在做什麼工作。

請記住,如果cursor在任何後代的CSS中設置,那麼將覆蓋body上的光標設置。

實施例:http://jsfiddle.net/88272/

還要注意,我拉伸width和主體的height100%


這裏有一個可能的解決方案,如果其他元素被覆蓋。

添加到您的CSS:

body.isWaiting, body.isWaiting * { 
    cursor:wait !important; 
} 

...然後執行:

document.body.className = 'isWaiting'; 

例子:http://jsfiddle.net/88272/3/

你需要測試瀏覽器的兼容性。


編輯:

因爲它聽起來好像你不能在服務器端添加自己的樣式表,你可以嘗試,而不是通過JavaScript添加一個。

例子:http://jsfiddle.net/88272/4/

// string representation of stylesheet content 
var styles = 'body.isWaiting, body.isWaiting * {cursor:wait !important;}'; 

    // grab the <head> element 
var head = document.getElementsByTagName('head')[0]; 

    // create a new "style" element, and set up its properties/content 
var sheet = document.createElement('style'); 
sheet.setAttribute('media', 'all'); 
sheet.setAttribute('type', 'text/css'); 

if(sheet.styleSheet) { 
    sheet.styleSheet.cssText = styles; // For IE 
} else { 
    sheet.appendChild(document.createTextNode(styles)); 
} 

    // append the new <style> element to the <head> 
head.appendChild(sheet); 

    // give the <body> the class when it is needed 
document.body.className = 'isWaiting';