如何使用jquery/javascript使光标停留为文本上的指针

How do I make the cursor stay as a pointer on text using jquery/javascript?

本文关键字:文本 指针 停留 光标 jquery 何使用 javascript      更新时间:2023-09-26

我只是希望光标在经过我的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中做到这一点。谢谢!

您的div id test不是testjquery

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


只能使用的更新
$("#test").hover(function () {
    $(this).css({
        'cursor': 'pointer'
    });
});

阅读 当用户将鼠标悬停在列表项上时,如何使光标成为手形? 正如FRNHR所评论

的那样