是否可以简单地将光标设置为“等待”整个 html 页面?这个想法是为了向用户展示当一个 ajax 调用完成时正在发生的事情。下面的代码显示了我尝试的一个简化版本,也演示了我遇到的问题:
测试:
<html>
<head>
<style type="text/css">
#id1 {
background-color: #06f;
cursor: pointer;
}
#id2 {
background-color: #f60;
}
</style>
</head>
<body>
<div id="id1">cursor: pointer</div>
<div id="id2">no cursor</div>
<a href="#" onclick="document.body.style.cursor = 'wait'; return false">Do something</a>
</body>
</html>
稍后编辑..。
它可以在 Firefox 和 IE 中使用:
div#mask { display: none; cursor: wait; z-index: 9999;
position: absolute; top: 0; left: 0; height: 100%;
width: 100%; background-color: #fff; opacity: 0; filter: alpha(opacity = 0);}
<a href="#" onclick="document.getElementById('mask').style.display = 'block'; return false">
Do something</a>
这个解决方案的问题(或特点)在于它会阻止点击,因为重叠的 div (感谢 Kibbee)
稍后编辑..。
多沃德提出了一个更简单的解决方案:
.wait, .wait * { cursor: wait !important; }
然后
<a href="#" onclick="document.body.className = 'wait'; return false">Do something</a>
此解决方案只显示等待光标,但允许单击。