开发者

Mouseover event in jQuery

开发者 https://www.devze.com 2023-04-02 06:01 出处:网络
I have the following mouseover function: $(\'.msg_id\').live("mouseover", function() { $(this).css(\'cursor\', \'pointer\');

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 onc开发者_JS百科e. How can I fix it? I have also tried mouseenter, but it fires in a loop too.


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.


You want to use mouseenter

0

精彩评论

暂无评论...
验证码 换一张
取 消