2011-01-11 89 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';