gpt4 book ai didi

javascript - jquery悬停不触发

转载 作者:技术小花猫 更新时间:2023-10-29 12:06:26 25 4
gpt4 key购买 nike

我在 domready 之后添加带有套接字消息的新客户端。我想在悬停时展开它们。

在这里阅读了一些答案,但没有任何效果。我不知道为什么

我试过了

socket.on('newStudentJoined', function studentJoined(msg) {
console.log(msg.student + ' joined the room');
$(document.createElement('div'))
.attr('class', 'studentIcon closed col-md-2 ' + msg.student)
.text(msg.student + ' 4r3 g345t g354 g54 ght65 g45t 3f4 f4 f4 534 g534')
.on('hover', function() {
console.log('hovering');
$(this).toggleClass('closed').toggleClass('open');
})
.appendTo('#joinedClients');
});

$('.studentIcon').on('hover', function() {
console.log('hovering');
$(this).toggleClass('closed').toggleClass('open');
});

但即使是“悬停”的控制台日志也没有出来。选择器是正确的,如果我记录它,它会突出显示确切的元素。确保:

<div id="joinedClients" class="row">
<div class="studentIcon closed col-md-2 test">test 4r3 g345t g354 g54 ght65 g45t 3f4 f4 f4 534 g534</div>
</div>

这是怎么回事?

最佳答案

改用mouseover

$(document).on('mouseover', '.studentIcon',function() {
console.log('hovering');
$(this).toggleClass('closed').toggleClass('open');
});

或使用

$(document).on("mouseenter mouseleave", ".studentIcon", function (e) {
if (e.type == "mouseenter") {
// check if it is mouseenter, do something
} else {
// if not, mouseleave, do something
}
});

The .hover() method binds handlers for both mouseenter and mouseleave events. You can use it to simply apply behavior to an element during the time the mouse is within the element.

关于javascript - jquery悬停不触发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35139071/

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