简体   繁体   English

在Javascript或jQuery中更改鼠标光标

[英]Change mouse cursor in Javascript or jQuery

How can I change the mouse cursor in Javascript or in jQuery ? 如何在Javascript或jQuery中更改鼠标光标? I know it's a very classic question, but very strangely this JSFiddle doesn't work : http://jsfiddle.net/2Qffw/ . 我知道这是一个非常经典的问题,但很奇怪这个JSFiddle不起作用: http//jsfiddle.net/2Qffw/

Here is the code : 这是代码:

$('body').css('cursor','pointer');

document.body.style.cursor = "pointer";

Do it in both html and body : htmlbody中都这样做:

$('html,body').css('cursor','crosshair');

http://jsfiddle.net/2Qffw/3/ http://jsfiddle.net/2Qffw/3/

It does work, but you had an empty body. 它确实有效,但你有一个空体。

http://jsfiddle.net/z6mhH/ http://jsfiddle.net/z6mhH/

HTML HTML

<body>
    asdasdasdasdads
</body>

JS JS

document.body.style.cursor = "crosshair";
document.getElementById("mydiv").style.cursor="move";

in Javascript, you can do it, you just have to use void 0; 在Javascript中,你可以做到,你只需要使用void 0; at the end of document.body.style.cursor = "crosshair"; document.body.style.cursor = "crosshair";的末尾document.body.style.cursor = "crosshair"; , so at the end, it should look like this: document.body.style.cursor = "crosshair"; void 0; ,所以最后,它应该是这样的: document.body.style.cursor = "crosshair"; void 0; document.body.style.cursor = "crosshair"; void 0; .

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM