gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-04 14:21:26 25 4
gpt4 key购买 nike

我只希望光标在经过我的 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com