2009-12-03 34 views

回答

212
$('selector').css('cursor', 'pointer'); 

我知道你的原始问题可能会引起混淆,但“finger”游标实际上被称为“指针”。

正常的箭头光标只是“默认”。

all possible default pointer looks DEMO

+14

如果可能的话,通过CSS做到这一点(有说:悬停选择器),并完全避免的jQuery。 – 2009-12-03 23:06:41

+8

@The Who - 当然,但是如果改变光标是依赖于JS的功能的一部分(假设你有一个滑块),那么如果用户关闭了JS,你不会希望光标改变。 – 2011-07-08 18:46:46

+2

我用''('selector').css('cursor','auto');'将鼠标移出指针区域时去掉样式。使用'$('...')。addClass('someclass')'和'$('...')。removeClass('someclass')' – jocull 2011-11-14 04:07:38

16

更新!新&改进!查找插件@GitHub


在另一方面,虽然that method很简单,我创建了一个jQuery插件(found at this jsFiddle, just copy and past code between comment lines),使得改变任何元素上的光标那样简单$("element").cursor("pointer")

但这还不是全部!立即行动,您将获得免费的手功能position & ishover!没错,2个非常方便的光标功能...免费!

他们的工作所看到的演示那样简单:

$("h3").cursor("isHover"); // if hovering over an h3 element, will return true, 
    // else false 
// also handy as 
$("h2, h3").cursor("isHover"); // unless your h3 is inside an h2, this will be 
    // false as it checks to see if cursor is hovered over both elements, not just the last! 
// And to make this deal even sweeter - use the following to get a jQuery object 
//  of ALL elements the cursor is currently hovered over on demand! 
$.cursor("isHover"); 

另外:

$.cursor("position"); // will return the current cursor position as { x: i, y: i } 
    // at anytime you call it! 

供应是有限的,所以立即行动!

+3

大声笑,没有理由的减号,猜测“H8Rz去h8” – SpYk3HH 2012-04-27 15:24:26

+3

哈哈谢谢你这个 – Andrew 2012-04-27 17:44:37

4

如何将光标更改为手指(如点击链接)而不是常规指针?

这是非常简单的实现使用CSS属性cursor,没有jQuery需要。

你可以阅读更多关于:CSS cursor propertycursor - CSS | MDN

.default { 
 
    cursor: default; 
 
} 
 
.pointer { 
 
    cursor: pointer; 
 
}
<a class="default" href="#">default</a> 
 

 
<a class="pointer" href="#">pointer</a>

0

这是非常简单的

HTML

<div> 
<input type="text" placeholder="sometext" /> 

<input type="button" value="button" class="button"/> 
<br/><br/> 
<button class="button"> Another button</button> 
</div> 

jQuery的

$(document).ready(function(){ 
$('.button').css('cursor', 'pointer'); 

// for old IE browsers 

$('.button').css('cursor', 'hand'); 

}); 

Check it out on JSfiddle