开发者

jquery live problem

开发者 https://www.devze.com 2023-03-04 16:27 出处:网络
guys, i got a problem here, any 1 can help?^^ in this program i tried to use live(for ajax issue) <div id=\"rpt1\" class=\"test\"></div>

guys, i got a problem here, any 1 can help?^^

in this program i tried to use live(for ajax issue)

<div id="rpt1" class="test"></div>
<div id="rpt2" class="test"></d开发者_StackOverflowiv>
<div id="rpt3" class="test"></div>
<div id="rpt4" class="test"></div>
<div id="rpt5" class="test"></div>

$('.test').live('click',test2);

after that i tried to unbind or die one of the handler

$('#rpt1').die('click');

if i use

 $('.test').die('click');

i will die all ..... which is the last thing i wanna do. i but the event still binded. i wondering how to solve this.. tried for several hour edi .. thx ^^

may b i put the live code here. i got lot of these div

 {$lang.report}
  • {$lang.re.spam}
  • and then the live at here $(".report").live('click',function(){

                                if($(this).next(".report_type").is(':visible')){
                                        $(this).next(".report_type").hide();
                                }else{
                                        $(this).next(".report_type").show()
                                }
                                        return false;
                                });
    

    function report_comment(category,comment_id,report_type) { blah blah blah $('#report'+comment_id).die('click'); }


    You need to pass the callback function as the second argument $('.test').die('click',test2);

    see: http://api.jquery.com/die/#die2

    Edit:

    I misunderstood your question.

    try this $('#rpt1').removeClass('test'); to remove the live event from one of the divs

    Example: http://jsfiddle.net/herostwist/TEZhb/


    try passing handler to die

    $('.test').die('click',test2);


    Try this:

         $('.test').live('click',function(){
            var $id = $("#" + $(this).attr('id'));
    
            if($id.next().is(':visible')){
                    $id.die('click');
                    $(id).next().hide();
            } else { 
                    $id.die('click');
                    $id.next().show();
            }
         });
    


    I think your missing a very important peace of information from .die()

    Note: Up to jQuery 1.4.4, in order for .die() to function correctly, the selector used with it must match exactly the selector initially used with .live().

    every example they give the click and die is applied to the same selector

    0

    精彩评论

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