在 Javascript 或 jQuery 中更改鼠标光标
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17414034/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Change mouse cursor in Javascript or jQuery
提问by Arnaud
How can I change the mouse cursor in Javascript or in jQuery ? I know it's a very classic question, but very strangely this JSFiddle doesn't work : http://jsfiddle.net/2Qffw/.
如何在 Javascript 或 jQuery 中更改鼠标光标?我知道这是一个非常经典的问题,但很奇怪,这个 JSFiddle 不起作用:http: //jsfiddle.net/2Qffw/。
Here is the code :
这是代码:
$('body').css('cursor','pointer');
document.body.style.cursor = "pointer";
回答by elclanrs
Do it in both html
and body
:
这样做既中html
和body
:
$('html,body').css('cursor','crosshair');
回答by Aart Stuurman
It does work, but you had an empty body.
它确实有效,但你的身体是空的。
HTML
HTML
<body>
asdasdasdasdads
</body>
JS
JS
document.body.style.cursor = "crosshair";
回答by john ktejik
document.getElementById("mydiv").style.cursor="move";
回答by G Phip
in Javascript, you can do it, you just have to use void 0;
at the end of document.body.style.cursor = "crosshair";
, so at the end, it should look like this: document.body.style.cursor = "crosshair"; void 0;
.
在 Javascript 中,你可以做到,你只需要void 0;
在 的末尾使用document.body.style.cursor = "crosshair";
,所以最后应该是这样的:document.body.style.cursor = "crosshair"; void 0;
。