jQuery Javascript 悬停光标指针
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14092766/
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
Javascript Hover Cursor Pointer
提问by DJ Howarth
Trying to use Jquery to do a Cursor Pointer on hover:
尝试使用 Jquery 在悬停时执行光标指针:
$('#example td').hover(function() {
$(this).css('cursor','pointer');
});
I do not want to put it in CSS, I want it in Jquery.
我不想把它放在 CSS 中,我想把它放在 Jquery 中。
What do I need to do to fix this?
我需要做什么来解决这个问题?
回答by Hans Vn
It seems to work here after I cleared up your jquery, you forgot to close the first click function and the searchform and button aren't declared in your html (i changed it to #example tr)
在我清除了您的 jquery 后,它似乎在这里工作,您忘记关闭第一个点击功能,并且您的 html 中未声明搜索表单和按钮(我将其更改为 #example tr)
Basically your jQuery wasn't that well coded (there also was a line with 5.}) on it that didn't belong there).
基本上你的 jQuery 没有那么好编码(也有一行 5.})不属于那里)。
I also set the "your framework" to jQueryinstead of the standard selected mooTools
我还将“你的框架”设置为jQuery而不是标准选定的mooTools
This is the complete jQuery code I got after i deleted some unnecessary code:
这是我删除了一些不必要的代码后得到的完整 jQuery 代码:
$(document).ready(function() {
$('#example tr').click(function() {
var href = $(this).find("a").attr("href");
if(href) {
window.location = href;
}
});
$('#example tr').hover(function() {
$(this).css('cursor','pointer');
});
});
回答by banzomaikaka
I couldn't comment Tobias Nilsons's answer for some reason, so here it is as an answer.
由于某种原因,我无法评论 Tobias Nilsons 的回答,所以这里是一个答案。
$('#example td').css('cursor', 'pointer');`
There's no reason why'd you want specify the style as applied on hover anyway. The cursor really only appears on hover, so.
无论如何,您没有理由要指定悬停时应用的样式。光标实际上只出现在悬停时,所以。
The fiddle: http://jsfiddle.net/Egttj/15/
小提琴:http: //jsfiddle.net/Egttj/15/
I'm assuming simply specifying the corresponding rule in a stylesheet causes a little trouble for you. But, yes, as everyone pointed out, it would really be the best and simplest way to do it.
我假设简单地在样式表中指定相应的规则会给您带来一些麻烦。但是,是的,正如每个人所指出的,这确实是最好和最简单的方法。
回答by Chetabahana
Comparing the first method
比较第一种方法
$('#example tr').hover(function() {
$(this).css('cursor','pointer');
});
With the second method
用第二种方法
$('#example td').css('cursor', 'pointer');`
I would recommend to stick to the first since it can be extended to whatever jQuery we want like:
我建议坚持第一个,因为它可以扩展到我们想要的任何 jQuery:
$('#example tr').hover(function() {
$(this).css('cursor','pointer');
$(this).click(function() {
var href = $(this).find("a").attr("href");
if(href) {
window.location = href;
}
});
});