Mouseover problem

一个人想着一个人 提交于 2019-12-02 18:17:14

问题


I have the following mouseover function:

$('.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); ). The function "mouseover" is called in a loop. The ajax request is sent all the time while mouseovering it, not only once. How can I fix it? I have also tried mouseenter, but it fires in a loop too.


回答1:


You might want to use the mouseenter() event instead, as mouseover will fire upon every move inside the element.

$('.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.



回答2:


You want to use mouseenter



来源:https://stackoverflow.com/questions/7285902/mouseover-problem

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!