12

尝试使用 Jquery 在悬停时执行光标指针:

$('#example td').hover(function() {
$(this).css('cursor','pointer');
});

我不想把它放在 CSS 中,我想把它放在 Jquery 中。

我需要做什么来解决这个问题?

http://jsfiddle.net/Egttj/

4

3 回答 3

26

在我清理了你的 jquery 之后,它似乎在这里工作,你忘记关闭第一次点击功能,并且你的 html 中没有声明搜索表单和按钮(我将其更改为 #example tr)

基本上你的 jQuery 没有那么好编码(也有一行 5.})不属于那里)。

我还将“你的框架”设置为jQuery而不是标准选择的mooTools

这是我删除一些不必要的代码后得到的完整 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');
    });

});

小提琴

于 2012-12-30T17:29:42.527 回答
8

出于某种原因,我无法评论 Tobias Nilsons 的答案,所以这里是一个答案。

$('#example td').css('cursor', 'pointer');`

无论如何,您没有理由要指定悬停时应用的样式。光标实际上只出现在悬停时,所以。

小提琴:http: //jsfiddle.net/Egttj/15/

我假设简单地在样式表中指定相应的规则会给您带来一些麻烦。但是,是的,正如每个人都指出的那样,这确实是最好和最简单的方法。

于 2012-12-30T17:26:34.260 回答
1

比较第一种方法

$('#example tr').hover(function() {
    $(this).css('cursor','pointer');
});

用第二种方法

$('#example td').css('cursor', 'pointer');`

我建议坚持第一个,因为它可以扩展到我们想要的任何 jQuery:

$('#example tr').hover(function() {

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

    $(this).click(function() {
       var href = $(this).find("a").attr("href");
       if(href) {
          window.location = href;
       }
    });

});
于 2018-05-24T15:24:21.487 回答