[英]Mouseover event in jQuery
I have the following mouseover
function:我有以下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');
//});
});
It puts some html code inside .msg_id
( $("#"+tid).html(data);
).它在.msg_id
( $("#"+tid).html(data);
) 中放入了一些 html 代码。 The function mouseover
is called in a loop.函数mouseover
在循环中调用。 The ajax request is sent all the time while mouseovering it, not only once. ajax 请求在鼠标悬停时一直发送,而不仅仅是一次。 How can I fix it?我该如何解决? I have also tried mouseenter
, but it fires in a loop too.我也试过mouseenter
,但它也会循环触发。
You might want to use the mouseenter() event instead, as mouseover will fire upon every move inside the element.您可能希望改用mouseenter()事件,因为鼠标悬停将在元素内的每次移动时触发。
$('.msg_id').live("mouseenter", function() {
//Do work here
});
or if live isn't required, simply:或者如果不需要直播,只需:
$('.msg_id').mouseenter(function() {
//Do work here
});
你想使用mouseenter
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.