如何使用jquery / javascript使光标保持为文本指针?

时间:2013-11-11 01:31:17

标签: javascript jquery css hover cursor

我只希望光标在经过div中的文本时保持指针。使用cs,它可以工作,但是使用Jquery它会恢复为文本选择器。

这不起作用......

<style>
#test
{
    height: 300px;
    width: 300px;
    background: blue;
    position:absolute;
    top: 0px;
    left: 0px;
    font-size: 80px;
}

</style>
</head>
<body>
<div id="test">It's not a pointer!</div>
<script src='jquery-1.10.2.min.js'>
</script>
<script>
$(document).ready(function(){
    $("#testjquery").hover(function(){
        $(this).css({'cursor':'hand', 'cursor':'pointer'});
    });
});
</script>

虽然这很好......

<style>
#test
{
    height: 300px;
    width: 300px;
    background: blue;
    position:absolute;
    top: 0px;
    left: 0px;
    font-size: 80px;
}
#test:hover
{
    cursor: pointer;
    cursor: hand;
}
</style>
</head>
<body>
<div id="test">It's a pointer!</div>

看起来很奇怪,因为我认为jquery只是访问了css方法。 寻找解释,或更好的解决方案,如何在Jquery中执行此操作。 谢谢!

1 个答案:

答案 0 :(得分:1)

您的div为test而不是testjquery

$("#test").hover(function () {
    $(this).css({
        'cursor': 'hand',
        'cursor': 'pointer'
    });
});

<小时/> 更新您只能使用

$("#test").hover(function () {
    $(this).css({
        'cursor': 'pointer'
    });
});

How can I make the cursor a hand when a user hovers over a list item?

的评论阅读frnhr