gpt4 book ai didi

javascript - jQuery 中的鼠标悬停事件

转载 作者:行者123 更新时间:2023-11-28 21:17:07 25 4
gpt4 key购买 nike

我有以下mouseover功能:

$('.msg_id').live("mouseover", function() {
$(this).css('cursor', 'pointer');
tid = $(this).attr('id');
idx = $(this).attr('name');
resp="";

$.ajax({
async: false,
url: "log_msg.asp",
data: $("#msgForm").serialize() + "&aktion=popup&msg_id="+tid+"&msg_id"+idx,
success: function(data){
$("#"+tid).html(data);
}
});

//$.post("log_msg.asp", $("#msgForm").serialize() + "&aktion=popup&msg_id="+tid+"&msg_id"+idx,
//function(data) {

//}).success(function(){
//$("#"+tid).html(data);
//resp=data;
//$('#bub'+tid).css('display', 'block');
//popd.css('display', 'block');
//});
});

它将一些 html 代码放入 .msg_id 中( $("#"+tid).html(data); )。函数mouseover 在循环中被调用。当鼠标悬停在其上时,ajax 请求会一直发送,而不仅仅是一次。我该如何修复它?我也尝试过 mouseenter,但它也会循环触发。

最佳答案

您可能想使用mouseenter()相反,鼠标悬停将在元素内的每次移动时触发。

$('.msg_id').live("mouseenter", function() {
//Do work here
});

或者如果不需要现场直播,只需:

$('.msg_id').mouseenter(function() {
//Do work here
});

<强> MouseOver() :

  • 进入元素时触发,可以在任何子元素内部触发。

<强> MouseEnter():

  • 将在进入某个元素时触发,并且仅在该元素内触发。

关于javascript - jQuery 中的鼠标悬停事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7285902/

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