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

标签 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 中执行此操作。 谢谢!

最佳答案

你的 div id 是 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 评论的那样

关于javascript - 如何使用 jquery/javascript 使光标保持为文本上的指针?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19897520/

相关文章:

javascript - 如何从我的 jquery 函数返回值

javascript - ReactJS组件什么时候写 "function"?

javascript - 使用 RegEx 用字符串换行文本

javascript - AngularJS 仅在 ng-repeat 中显示最后一个元素

javascript - Jquery ajax 请求完成但 Axios 失败

javascript - 使用ajax请求获取上一个和下一个对象

javascript - jQuery:根据文本值对 <a> 链接进行分组

javascript - 如何在 jquery 选项卡中为 td 添加事件类?

css - 菜单调整到下一行而不是全宽

CSS3 圆 Angular 白色背景