简体   繁体   English

jQuery 中的鼠标悬停事件

[英]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
});

MouseOver() :鼠标悬停()

  • Will fire upon entering an element can fire inside of any child elements.进入元素时会触发可以在任何子元素内部触发。

MouseEnter():鼠标输入():

  • Will fire upon entering an element, and only that element.将在进入一个元素时触发,并且只有那个元素。

你想使用mouseenter

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM