我尝试使用MS CRM Dynamics 4.0的js来更改鼠标光标, 当我使用ajax调用方法时,我想将鼠标光标显示为等待: document.body.style.cursor="等待"; 但它不起作用...我该怎么做?
最佳答案
你正在做的事情有效。
请记住,如果在任何后代的 CSS 中设置了 cursor
,这将覆盖 body
上的光标设置。
示例: http://jsfiddle.net/88272/
另请注意,我将正文的宽度
和高度
拉伸(stretch)至100%
。
如果其他元素被覆盖,这是一个可能的解决方案。
将其添加到您的 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';
关于javascript - 通过js改变鼠标光标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4661793/