Change mouse cursor in Javascript or jQuery

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-23 07:00:07

问题


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/.

Here is the code :

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

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

回答1:


Do it in both html and body:

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

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




回答2:


It does work, but you had an empty body.

http://jsfiddle.net/z6mhH/

HTML

<body>
    asdasdasdasdads
</body>

JS

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



回答3:


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



回答4:


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;.



来源:https://stackoverflow.com/questions/17414034/change-mouse-cursor-in-javascript-or-jquery

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!